angular.module("myApp",[])
.controller("myCtrl",function($scope) {
$scope.persons = [{name:"teja",age:11},
{name:"Ash",age:12},
{name:"teja",age:11}];
});
In the realm of Angular, the presence of duplicate elements within an array declared in ng-repeat
is normally not allowed. However, there exists a solution by employing "track by $index
" which can accommodate duplicates within the array. This begs the question: How does ng-repeat
discern the existence of duplicates within the array? What criteria does it rely on to make this determination? It's worth noting that when a new object is created, a new reference for that object is also generated. Yet in the provided code snippet, how does ng-repeat
manage to pinpoint the duplicates.
<div ng-repeat="person in persons">
{{ person.name }}
</div>