English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-repeat directive

AngularJS Reference Manual

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-repeat="x in records">{{x}}</h1>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    "Basic Tutorial Website"1",
    "Basic Tutorial Website"2",
    "Basic Tutorial Website"3",
    "Basic Tutorial Website"4",
  ]
});
</script>
</body>
</html>
Test See ‹/›

Definition and usage

ng-repeat The directive is used to output a specified number of HTML elements repeatedly.

The collection must be an array or an object.

Syntax

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

All HTML elements support this directive.

Parameter value

ValueDescription
expressionThe expression defines how to iterate over a collection.
Expression example rules:
x in records
  (key, value) in myObj
x in records track by $id(x)

More examples

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js></script>
</head>
<body ng-app="myApp">
<table ng-controller="myCtrl" border="1">
<tr ng-repeat="x in records"
  <td>{{x.Name}}</td>
  <td>{{x.Country}}</td>  
</tr>
</table>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    {
      "Name": "Alfreds Futterkiste",
      "Country": "Germany"
    },
    {
      "Name": "Berglunds snabbk",
      "Country": "Sweden"
    },
    {
      "Name": "Centro comercial Moctezuma",
      "Country": "Mexico"
    },
    {
      "Name": "Ernst Handel",
      "Country": "Austria"
    }
  ]
});
</script>
</body>
</html>
Test See ‹/›
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js></script>
</head>
<body ng-app="myApp">
<table ng-controller="myCtrl" border="1">
<tr ng-repeat="(x, y) in myObj">
  <td>{{x}}</td>/td>
  <td>{{y}}</td>/td>  
</tr>
</table>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.myObj = {
    "Name": "Alfreds Futterkiste",
    "Country": "Germany",
    "City": "Berlin"
  }
});
</script>
</body>
</html>
Test See ‹/›

AngularJS Reference Manual