使用循环 ng-repeat 的时候报如下错误:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use ‘track by’ expression to specify unique keys. Repeater: attrOpt in attr.value, Duplicate key: string:2, Duplicate value: 2
解决办法是在循环 ng-repeat 中添加 track by:
<div ng-repeat=“item in items track by $index“></div>
或:
<div ng-repeat=“item in items track by item.id“></div>
或:
<div ng-repeat=“item in items track by customId(item)“></div>
原因:循环中 item 不能出现重复值。