首页 > 代码库 > [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq

[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq

angularjs 使用ng-repeat报错

 	
<div ng-init="words = ['高校','高校','高校']" ng-repeat="word in words">
    {{word}}
</div>

[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use ‘track by‘ expression to specify unique keys

  发现是由于同样的内容反复引起,解决方式

<div ng-init="words = ['高校','高校','高校']" ng-repeat="word in words track by $index">
    {{word}}
</div>

在ng-repeat后面加上

 track by $index


[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use &#39;track by&#39; expression to specify uniq