This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Updating track by $index usage #16334
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
* 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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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