问题
If during execution an item is added to an array that is rendered using ngRepeat, does it redraw all items?
回答1:
Since Angular 1.2 we have the 'track by' option which will prevent the repeater from re-rendering all the items.
Example:
ng-repeat="task in tasks track by task.id"
Check out this explanation : http://www.codelord.net/2014/04/15/improving-ng-repeat-performance-with-track-by/
回答2:
Yes, all items are redrawn.
In fact, the items may be redrawn at other times as well.
Example: When a value in a parent directive / template is updated. During the '$digest' loop, Angular will evaluate the scope tree and this will cause affected child components to be redrawn.
More information:
- http://docs.angularjs.org/guide/concepts#runtime
- http://docs.angularjs.org/api/ng.$rootScope.Scope#$digest
来源:https://stackoverflow.com/questions/16947108/does-ngrepeat-rerender-all-items-after-adding-an-new-item