所以我一直在使用 angularjs 和 symfony 开发一个应用程序。我试图每 5000 毫秒重复检索一次数据,因此我采用“$timeout”功能从服务器获取实时数据检索。
这是我的 Controller 代码:
.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 上加载,但错误部分中没有错误。有人请告诉我问题到底是什么......任何其他建议可以使实时检索发挥作用。提前致谢 。
最佳答案
要每 5000 毫秒获取一次数据,您应该使用
$interval service $interval
关于javascript - $数据刷新超时服务不起作用(Angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46616962/