This repository was archived by the owner on Apr 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 743
/
Copy pathngRepeat:dupes.html
17 lines (17 loc) · 1.78 KB
/
ngRepeat:dupes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<a href="http://github.com/angular/angular.js/edit/master/docs/content/error/ngRepeat/dupes.ngdoc" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">Duplicate Key in Repeater</code>
<div><span class="hint">error in component <code ng:non-bindable="">ngRepeat</code>
</span>
</div>
</h1>
<div><pre class="minerr-errmsg" error-display="Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}">Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}</pre>
<h2 id="description">Description</h2>
<div class="description"><div class="ngrepeat-page ngrepeat-dupes-page"><p>Occurs if there are duplicate keys in an <a href="api/ng.directive:ngRepeat"><code>ngRepeat</code></a> expression. Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items.</p>
<p>By default, collections are keyed by reference which is desirable for most common models but can be problematic for primitive types that are interned (share references).</p>
<p>For example the issue can be triggered by this <em>invalid</em> code:</p>
<pre><code><div ng-repeat="value in [4, 4]">
</div></code></pre>
<p>To resolve this error either ensure that the items in the collection have unique identity of use the <code>track by</code> syntax to specify how to track the association between models and DOM.</p>
<p>To resolve the example above can be resolved by using <code>track by $index</code>, which will cause the items to be keyed by their position in the array instead of their value:</p>
<pre><code><div ng-repeat="value in [4, 4] track by $index"></div></code></pre>
</div></div>
</div>