Jan Netherdrake Jan Netherdrake - 1 year ago 88
AngularJS Question

AngularJS ngRepeat update model

I use

to render a
html table
. My controller looks like so:

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

As you can see, I am updating the
array periodically. However, my view is constructed like so:

<tr ng-repeat="item in foo">

The problem is, when I update
, it doesn't re-render my table with new data.

How would I go about this problem?

Answer Source

Did you wrap the update in

$scope.$apply(function() {
  // update goes here

? This should solve the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download