ngRepeat
directive instantiates a template once per item from a collection. The collection must be an array or an object. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index
is set to the item index or key.
<element ng-repeat="expression"></element>
<div ng-repeat="(key, value) in myObj">...</div>
<div ng-repeat="variable in expression">...</div>
Variable | Details |
---|---|
$index | number iterator offset of the repeated element (0..length-1) |
$first | boolean true if the repeated element is first in the iterator. |
$middle | boolean true if the repeated element is between the first and last in the iterator. |
$last | boolean true if the repeated element is last in the iterator. |
$even | boolean true if the iterator position $index is even (otherwise false). |
$odd | boolean true if the iterator position $index is odd (otherwise false). |
AngularJS provides these parameters as special variables that are available in the ng-repeat expression and anywhere inside of the HTML tag on which the ng-repeat lives.