-
Notifications
You must be signed in to change notification settings - Fork 4
Angular.js
Angular requires the elements to be unique in ng-repeat array. To ensure this, Angular assign $$hashkey property to each element in the array and report error if it detects duplicate $$hashkey. In our system, multiple virtual browsers could share objects, the $$hashkey for those objects are assigned by isolated angular code, angular use an incremented counter to generate $$hashkey, so those objects will have duplicated $$hashcode.
Our solution is to provide an API to assign $$hashkey ourselves to the shared objects before they are seen by angular.
Another solution could be use the track by $index method to tell angular to identify those objects by index in the ng-repeat loop.
The problem about track by $index is that, angular will reuse the DOM objects instead of creating new DOM objects for new elements in array, deleting DOM for removed elements in array. When we remove elements from the head of an array, we will see a lot of DOM content updates. And all we do to the array in a ng-repeat loop is appending new elements at the tail of the array, removing elements from the head of the array, so track by $index is doing no good here.
http://www.williambrownstreet.net/blog/2014/04/faster-angularjs-rendering-angularjs-and-reactjs/