WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS ng-repeat Directive


Example

Write one header for every thing in the records array:

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-repeat="x in records">{{x}}</h1>

<script>
var application = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.records = [
        "Alfreds Futterkiste",
        "Berglunds snabbköp",
        "Centro comercial Moctezuma",
        "Ernst Handel",
    ]
});
</script>

</body>
Attempt it yourself »

Definition and Usage

The ng-repeat order rehashes a lot of HTML, a given number of times.

The set of HTML will be rehashed once per thing in a collection.

The accumulation must be an exhibit or an object.

Note: Each example of the redundancy is given its own scope, which comprise of the current item.

If you have a gathering of articles, the ng-repeat order is ideal for making a HTML table, showing one table column for each item, also, one table information for each article property. See model below.


Syntax

<element ng-repeat="expression"></element>

Supported by all HTML elements.


Parameter Values

Value Description
expression An articulation that determines how to circle the collection.

Legal Articulation examples:

x in records

(key, esteem) in myObj

x in records track by $id(x)

More Examples

Example

Write one table line for every thing in the records array:

<table ng-controller="myCtrl" border="1">
    <tr ng-repeat="x in records">
        <td>{{x.Name}}</td>
        <td>{{x.Country}}</td>
    </tr>
</table>

<script>
var application = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.records = [
       {
            "Name" : "Alfreds Futterkiste",
            "Nation" : "Germany"
        },{
            "Name" : "Berglunds snabbköp",
            "Nation" : "Sweden"
        },{
            "Name" : "Centro comercial Moctezuma",
            "Nation" : "Mexico"
        },{
            "Name" : "Ernst Handel",
            "Nation" : "Austria"
        }
    ]
});
</script>
Attempt it yourself »

Example

Write one table line for every property in an object:

<table ng-controller="myCtrl" border="1">
    <tr ng-repeat="(x, y) in myObj">
        <td>{{x}}</td>
        <td>{{y}}</td>
    </tr>
</table>

<script>
var application = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "Name" : "Alfreds Futterkiste",
        "Nation" : "Germany",
        "City" : "Berlin"
    }
});
</script>
Attempt it yourself »