我使用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