Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
* 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.
* `track by $index` can also provide a performance boost,
* but can cause unexpected side effects if not used correctly as noted below.
* </div>
*
* ```html
Expand All @@ -115,10 +116,12 @@
* <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.
* {@link guide/expression#one-time-binding one-time bindings} or {@link guide/directive#creating-directives directives}.
* In such cases, where the array changes and `track by $index` is in use the `nth` DOM element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where ... -> when ..
in use the -> in use, the

* will always be matched with the `nth` item of the array. Since ngRepeat thinks that this item is the same as before,
* it will not re-create the DOM, but keep the existing one (bound to the existing scope), and therefore
* any directives that appear on the template will not be re-compiled (since compilation/linking happens only when a new instance is created).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this line at 100 characters

* This is ngRepeats "keep track" function at play and it to reduce unnecessary DOM elements being rebuilt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this last sentence adds useful info.

* </div>
*
* When no `track by` expression is provided, it is equivalent to tracking by the built-in
Expand Down