我在使用 ng-repeat 更新 View 时遇到问题,该 View 在使用查询从服务器加载数据后不会刷新。
这是我的代码:
Controller :
vm.getPage = function() {
rendezvousResource.query(vm.gridOptions, function(result) {
vm.gridData.totalItems = result.total;
vm.gridData.totalPages = result.last_page;
vm.gridOptions.page = result.current_page;
vm.gridOptions.data = result.data;
vm.rendezvouss = result.data;
// $scope.$apply();
});
};
查看:
<table ng-controller="RendezvousListCtrl as vm" class="table table-hover">
<thead>
<tr>
<th>Client</th>
<th>Date Début</th>
<th>Date Fin</th>
<th>Type RDV</th>
<th>Status</th>
<th>Notification</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="rendezvous in vm.rendezvouss">
<td>{{ rendezvous.nomClient }}</td>
<td>{{ rendezvous.debut }}</td>
<td>{{ rendezvous.fin }}</td>
<td>{{ rendezvous.typerdv }}</td>
<td>{{ rendezvous.status }}</td>
<td>{{ rendezvous.notification }}</td>
</tr>
</tbody>
</table>
我已经尝试添加 $scope.$apply() 但我得到一个:Error: error:inprog 行动已在进行中
我已经在回调函数内尝试了 $timeout 但它不起作用,在 getPage 上应用它的函数之外,它说 undefined 不是一个函数。
我也尝试使用 .then 和 $promise.then 但它的答案也是 undefined is not a function。
请问有什么帮助吗? :)
最佳答案
我的 Controller 已实例化两次(我的错误),但这就是导致 ngRepeat 不刷新的原因。
为了能够看到这一点,我安装了 AngularJS Batarang chrome extension 。它提供了清晰的范围 View ,并且能够看到我的 Controller 已实例化两次。
关于javascript - Ng-Repeat 在资源查询后不更新 - $apply() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036481/