Ng-repeat doesn't work when an element is repeated in an object

This is my html

<div ng-app="person" ng-controller="names">
<div ng-repeat="id in ids">
{{id}}
</div>
</div>

      

This is my script

var persons=angular.module("person",[]);
persons.controller("names",function($scope){
$scope.ids=['vicky','a','c','svicky'];
});

      

This works fine as expected working fiddle

But when I change the last item from 'svicky' to 'vicky' it doesn't work

script that doesn't work

Why is this happening?

+3


source to share


1 answer


Use track by index as the console says. Fiddle

<div ng-app="person" ng-controller="names">
<div ng-repeat="id in ids track by $index">
{{id}}
</div>
</div>

      



This is the error you should see in the console with a non-working example:

Error: [ngRepeat: dupes] Duplicates in the repeater are not allowed. using 'track by'

+6


source







All Articles