AngularJS 使用ng-repeat报错 [ngRepeat:dupes]

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

AngularJS 使用ng-repeat报错 [ngRepeat:dupes]

  2020-05-15 我要评论

AngularJS 使用ng-repeat报错

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

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 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们