2

The AngularDart ng-repeat directive seems to require unique values; e.g., the following

  <li ng-repeat="x in ['Alice', 'Bob', 'Alice']">...</li>

results in

  [NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. 
  Use 'track by' expression to specify unique keys.

Assuming that the list of strings is obtained from some external source and that uniqueness of values is not guaranteed, how can the [NgErr50] be avoided?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Patrice Chalin
  • 15,440
  • 7
  • 33
  • 44
  • 1
    possible duplicate of [ng-repeat not working over collections that contains dupes](http://stackoverflow.com/questions/20452223/ng-repeat-not-working-over-collections-that-contains-dupes) – Günter Zöchbauer Feb 13 '14 at 19:11

1 Answers1

6

This works:

  <li ng-repeat="x in ['Alice', 'Bob', 'Alice'] track by $index">...</li>

For more options, see the ng-repeat API docs.

Patrice Chalin
  • 15,440
  • 7
  • 33
  • 44