docs(ngRepeat): add warning about track by $index with one-time bindings
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
* # Tracking and Duplicates
|
||||
*
|
||||
* `ngRepeat` uses {@link $rootScope.Scope#$watchCollection $watchCollection} to detect changes in
|
||||
* the collection. When a change happens, ngRepeat then makes the corresponding changes to the DOM:
|
||||
* the collection. When a change happens, `ngRepeat` then makes the corresponding changes to the DOM:
|
||||
*
|
||||
* * When an item is added, a new instance of the template is added to the DOM.
|
||||
* * When an item is removed, its template instance is removed from the DOM.
|
||||
@@ -70,7 +70,7 @@
|
||||
*
|
||||
* To minimize creation of DOM elements, `ngRepeat` uses a function
|
||||
* to "keep track" of all items in the collection and their corresponding DOM elements.
|
||||
* For example, if an item is added to the collection, ngRepeat will know that all other items
|
||||
* For example, if an item is added to the collection, `ngRepeat` will know that all other items
|
||||
* already have DOM elements, and will not re-render them.
|
||||
*
|
||||
* The default tracking function (which tracks items by their identity) does not allow
|
||||
@@ -97,19 +97,29 @@
|
||||
* ```
|
||||
*
|
||||
* <div class="alert alert-success">
|
||||
* If you are working with objects that have an identifier property, you should track
|
||||
* by the identifier instead of the whole object. Should you reload your data later, `ngRepeat`
|
||||
* If you are working with objects that have a unique identifier property, you should track
|
||||
* by this identifier instead of the object instance. Should you reload your data later, `ngRepeat`
|
||||
* will not have to rebuild the DOM elements for items it has already rendered, even if the
|
||||
* JavaScript objects in the collection have been substituted for new ones. For large collections,
|
||||
* this significantly improves rendering performance. If you don't have a unique identifier,
|
||||
* `track by $index` can also provide a performance boost.
|
||||
* </div>
|
||||
*
|
||||
* ```html
|
||||
* <div ng-repeat="model in collection track by model.id">
|
||||
* {{model.name}}
|
||||
* </div>
|
||||
* ```
|
||||
*
|
||||
* <br />
|
||||
* <div class="alert alert-warning">
|
||||
* Avoid using `track by $index` when the repeated template contains
|
||||
* {@link guide/expression#one-time-binding one-time bindings}. In such cases, the `nth` DOM
|
||||
* element will always be matched with the `nth` item of the array, so the bindings on that element
|
||||
* will not be updated even when the corresponding item changes, essentially causing the view to get
|
||||
* out-of-sync with the underlying data.
|
||||
* </div>
|
||||
*
|
||||
* When no `track by` expression is provided, it is equivalent to tracking by the built-in
|
||||
* `$id` function, which tracks items by their identity:
|
||||
* ```html
|
||||
@@ -118,15 +128,17 @@
|
||||
* </div>
|
||||
* ```
|
||||
*
|
||||
* <br />
|
||||
* <div class="alert alert-warning">
|
||||
* **Note:** `track by` must always be the last expression:
|
||||
* </div>
|
||||
* ```
|
||||
* <div ng-repeat="model in collection | orderBy: 'id' as filtered_result track by model.id">
|
||||
* {{model.name}}
|
||||
* </div>
|
||||
* <div ng-repeat="model in collection | orderBy: 'id' as filtered_result track by model.id">
|
||||
* {{model.name}}
|
||||
* </div>
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* # Special repeat start and end points
|
||||
* To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
|
||||
* the range of the repeater by defining explicit start and end points by using **ng-repeat-start** and **ng-repeat-end** respectively.
|
||||
|
||||
Reference in New Issue
Block a user