Ng-Repeat-3

 

In this example we bind the numbers array with some duplicate values (2 is two times in the array) with the div tag using ng-repeat directive. As there are duplicate values so we have to track this array by $index. Using the ng-repeat directive we print the index of the array element and value on the index, Use 'track by' expression to specify unique keys. See the output.

 
 
 
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <div ng-repeat="n in [2,2, 4, 6, 8,10,12] track by $index"> Index - {{$index}} ______________ Value - {{n}} </div> </div> </body> </html>
Output