AngularJS 使用ng-repeat報錯

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

    ng-repeat報錯html

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

  發現是由於相同的內容重複引發,解決方案express

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

 在ng-repeat後面加上spa

1 track by $index

 

1
相關文章
相關標籤/搜索