Patrice Chalin
Patrice Chalin

Reputation: 16100

How to use AngularDart ng-repeat over a list of simple values possibly with duplicates

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?

Upvotes: 2

Views: 1947

Answers (1)

Patrice Chalin
Patrice Chalin

Reputation: 16100

This works:

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

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

Upvotes: 6

Related Questions