Skip to content

Commit 2d7cb9b

Browse files
bchernynetman92
authored andcommitted
docs(ngRepeat): document that track by must be the last expression
this is a point of confusion that's not well documented. see angular#5520 Closes angular#11934
1 parent 610414f commit 2d7cb9b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ng/directive/ngRepeat.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@
9797
* </div>
9898
* ```
9999
*
100+
* <div class="alert alert-warning">
101+
* **Note:** `track by` must always be the last expression:
102+
* </div>
103+
* ```
104+
* <div ng-repeat="model in collection | orderBy: 'id' as filtered_result track by model.id">
105+
* {{model.name}}
106+
* </div>
107+
* ```
108+
*
100109
* # Special repeat start and end points
101110
* To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
102111
* the range of the repeater by defining explicit start and end points by using **ng-repeat-start** and **ng-repeat-end** respectively.
@@ -168,8 +177,9 @@
168177
* which can be used to associate the objects in the collection with the DOM elements. If no tracking expression
169178
* is specified, ng-repeat associates elements by identity. It is an error to have
170179
* more than one tracking expression value resolve to the same key. (This would mean that two distinct objects are
171-
* mapped to the same DOM element, which is not possible.) If filters are used in the expression, they should be
172-
* applied before the tracking expression.
180+
* mapped to the same DOM element, which is not possible.)
181+
*
182+
* Note that the tracking expression must come last, after any filters, and the alias expression.
173183
*
174184
* For example: `item in items` is equivalent to `item in items track by $id(item)`. This implies that the DOM elements
175185
* will be associated by item identity in the array.

0 commit comments

Comments
 (0)