Ng-Repeat-1

 

We have an array named students with the name of the students $scope.students = [{ name: 'John' }, { name: 'Smith' }, { name: 'Allen' }, { name: ' Johnson' }, { name: 'Harris' }, { name: ' Williams' }, { name: 'David' }]; The ng-repeat directives is same as for loop, Here is how we use ng-repeat ng-repeat="student in students" In this example the ng-repeat directive will print student name one by one in the li tag as the student variable will hold the object from the array one by one and we print the student.name which will display the student name in the list.

 
 
 
<!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"> <ul> <li ng-repeat="student in students">{{student.name}}</li> </ul> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.students = [{ name: 'John' }, { name: 'Smith' }, { name: 'Allen' }, { name: ' Johnson' }, { name: 'Harris' }, { name: ' Williams' }, { name: 'David' }]; }]); </script> </body> </html>
Output