javascript - Performance of ng-repeat with dynamically generated array of data -


let's have array of objects , each object has unique id , text property.

now, let's have ng-repeat one:

controller

$scope.data = my_arr; 

view

<div ng-repeat="for elem in data track elem.id">     {{ elem.text }} </div> 

special note on track by.

what happen if assigned new array data variable ($scope.data = new_arr;), if content of new array:

  • is identical previous one
  • it contains 1 new element
  • it contais elements except 1

will angularjs smart enough to:

  • not re-render div elements
  • append/insert new div element dom
  • hide/delete div isn't contained in new array

since you’re using track elem.id, angular reuse dom elements. add or remove 1 element document tree. per the docs:

should reload data later, ngrepeat not have rebuild dom elements items has rendered, if javascript objects in collection have been substituted new ones.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -