Does ngRepeat rerender all items after adding an new item?

巧了我就是萌 提交于 2019-12-05 20:09:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!