0

How to update data for ng-repeat between view and controller? If I put:

ng-repeat="item in actions"

And if I change $scope.actions in controller to some other value, would it be updated in ng-repeat? Is this the best way to update data values for ng-repeat between view and controller?

firstChild
  • 326
  • 2
  • 12
  • 4
    Yes. To both your questions. I'll expand on that a bit by saying the use of `track by` could make DOM rendering more efficient, depending on your usage (note: you can track by an array if `$index` may be inconsistent and your objects have composite keys). http://www.bennadel.com/blog/2556-using-track-by-with-ngrepeat-in-angularjs-1-2.htm – David Williams Feb 09 '15 at 08:36

1 Answers1

1

ng-repeat is slow, you will know when you have good amount of data to start researching about better performance of ng-repeat.

You first question

if I change $scope.actions in controller to some other value, would it be updated in ng-repeat?

Yes, however if it doesn't work use angular's '$timeout'

$timeout(function(){
  $scope.actions = [];
},0)

Your second question

Is this the best way to update data values for ng-repeat between view and controller?

it is the best way though it is suggested supplementing ng-repeat with limitTo together with Infinite scrolling.

Take a look at this stack overflow question

Community
  • 1
  • 1
Nick Satija
  • 181
  • 7