我ng-repeat用来渲染一个html table。我的控制器看起来像这样:
ng-repeat
html table
app.controller("fooCtrl", function($scope, WebSocket) { $scope.foo = [ ... ]; WebSocket.start(function(data) { // this is a callback on websocket.onmessage // here is a for loop iterating through $scope.foo objects and updating them }); });
如您所见,我正在$scope.foo定期更新阵列。但是,我的观点是这样构造的:
$scope.foo
<tr ng-repeat="item in foo"> ... </tr>
问题是,当我更新时foo,它不会用新数据重新渲染我的表。
foo
我将如何解决这个问题?
您是否将更新包入
$scope.$apply(function() { // update goes here });
?这应该可以解决问题。