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

来源:互联网 发布:linux时间同步 chrony 编辑:程序博客网 时间:2024/06/06 00:37

angularjs 使用ng-repeat报错

[html] view plain copy
  1.       
  2. <div ng-init="words = ['高校','高校','高校']" ng-repeat="word in words">  
  3.     {{word}}  
  4. </div>  

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

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

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

在ng-repeat后面加上

[html] view plain copy
  1. track by $index  
0 0