ng-repeat directive repeats the HTML elements. Let us see this with the help of an example.
Write the following HTML mark up in the webpage.
- <!doctype html>
- <html ng-app>
- <head>
- <title>My Angular App</title>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
- </head>
- <body>
- <div ng-app="" ng-init="cities=['New Delhi','Mumbai','Pune']">
- <ul>
- <li ng-repeat="x in cities">
- {{ x }}
- </li>
- </ul>
- </div>
- </body>
- </html>
So let us check the output of the program.

Let us try one more example that deals with an array of objects. Write the below code in the webpage.
- <!doctype html>
- <html ng-app>
- <head>
- <title>My Angular App</title>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
- </head>
- <body>
- <div ng-app="" ng-init="data=[
- {State:'Maharashtra',city:'Mumbai'},
- {State:'Goa',city:'Panjim'},
- {State:'Karnataka',city:'Bengaluru'}]">
- <ul>
- <li ng-repeat="x in data">
- {{ x.State + ', ' + x.city }}
- </li>
- </ul>
- </div>
- </body>
- </html>
Let us check the output now.

This is how ng-repeat works in Angular JS.

Debasis SahaPosted May 11, 2016, 4:27 AM
Nice one..