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
divelements - append/insert new
divelement dom - hide/delete
divisn'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,
ngrepeatnot have rebuild dom elements items has rendered, if javascript objects in collection have been substituted new ones.
Comments
Post a Comment