所以我一直在使用angularjs和symfony的应用程序工作。我试图每5000毫秒检索一次重复的数据,所以我使用“$超时”功能从服务器获取实时数据。
这里是我的控制器代码:
.controller('clientController', [ '$rootScope','$scope', 'Api' , 'toastr',
'$window', '$routeParams', '$filter' , '$timeout',
function($rootScope,$scope, Api ,toastr, $window, $routeParams, $filter ,
$timeout) {
$rootScope.myVar=true;
$scope.clients = [];
var retrieveItems = function() {
Api.getAllClients()
.then(function (result) {
console.log('result', result);
$scope.clients = result.data;
$timeout(retrieveItems, 5000);
}, function (error) {
console.log('error', error);
});
};
...
}])
这里的VUE代码:
<table class="table table-striped table-bordered" id="editable-datatable">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>tel</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="client in clients" id="1" class="gradeX">
<td>{{client.username}}</td>
<td>{{client.email}}</td>
<td>{{client.tel}}</td>
<td collapse=3>
<a style="border: 1px solid rgba(10, 6, 6, 0.25); padding: 4px;" ng-href="#!/client/{{client.id}}" ng-click="ClientDetailsController()">
<i class="icon-eye-open"></i> Details
</a>
<span style="margin-left: 10px"><a data-toggle="modal" href data
target="#exampleModal" ng-click="setID(client.id)" >
<i class="icon-remove-sign"></i> Delete
</a></span>
</td>
</tr>
</tbody>
</table>
我的问题是,每当我去掉 “retrieveItems” 功能一切正常就好了。我得到所有的客户端,但是何时添加超时服务,所以我可以每隔5秒刷新注册的客户端...客户端不会加载vue,但在错误部分没有错误。有人请启发我究竟是什么问题可能..任何其他建议,使实时检索功能。提前致谢 。
我认为你必须添加$范围。$适用()。 –
嗨!非常感谢您的答复。请您告诉我我到底要把它放在哪里? – Amy
你的代码看起来不错,也许你总是得到相同的数据 –