Ng-Repeat-4

 

In this example, we have an array of students with id and name of the student. We print the name of the student using ng-repeat directive and we track this array by student id. if there are two or more students with the same id then this ng-repeat directive will display nothing. Let's see the example:

 
 
 
<!DOCTYPE html> <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="app"> <div ng-controller="controllerName"> <div ng-repeat="student in students track by student.id"> {{student.name}} </div> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.students = [{ id: '1', name: 'Smith' }, { id: '2', name: 'Allen' }, { id: '3', name: 'David' }, { id: '4', name: 'John' }, { id: '5', name: 'John' }, { id: '6', name: 'John' }]; }]); </script> </body> </html>
Output