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

笑着哭i 提交于 2019-12-24 01:54:21

问题


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?


回答1:


This works:

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

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



来源:https://stackoverflow.com/questions/21763136/how-to-use-angulardart-ng-repeat-over-a-list-of-simple-values-possibly-with-dupl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!