我使用ng-repeat
呈现html table
。我的控制器看起来像这样:AngularJS ngRepeat更新模型
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
阵列。然而,我的观点是构建像这样:
<tr ng-repeat="item in foo">
...
</tr>
的问题是,当我更新foo
,它不会重新渲染我的表用新的数据。
我该如何解决这个问题?
嗨,你是否知道如何将一个项目添加到ng-repeat列表的顶部?我可以更新我的列表 - 新的项目被渲染,但它到达列表的底部。 – lulu88