AngularJS 使用ng-repeat报错

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

    ng-repeat报错

1 <div ng-init="words = ['高校','高校','高校']" ng-repeat="word in words"> 
2   {{word}}
3 </div>
1 [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

  发现是因为相同的内容重复引起,解决方案

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

 在ng-repeat后面加上

1 track by $index

 

1
 
posted @ 2018-01-02 10:28  ngulc  阅读(545)  评论(0编辑  收藏  举报