Below snippet doesn't run. What am I missing here with ng-init?!! If I change array values to 'non-repeating' values it works. For example, changing names=['Jani','Hege','Kavi','Kavi2'] it works.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<body>
<div ng-app="" ng-init="names=['Jani','Hege','Kavi','Kavi']">
<p>Looping with ng-repeat:</p>
<ul>
<li ng-repeat="x in names">
{{ x }}
</li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:1)
此track by $index
:您可以查看文档 - Tracking and Duplicates
<li ng-repeat="x in names track by $index">
{{ x }}
</li>