ngRepeat
(directive in module ng
)
The ngRepeat
directive instantiates a template once per item from a collection. 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.
Special properties are exposed on the local scope of each template instance, including:
$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.<ANY ng-repeat="{repeat_expression}"> ... </ANY>as class
<ANY class="ng-repeat: {repeat_expression};"> ... </ANY>
ngRepeat – {repeat_expression} –
The expression indicating how to enumerate a collection. Two formats are currently supported:
variable in expression
– where variable is the user defined loop variable and expression
is a scope expression giving the collection to enumerate.
For example: track in cd.tracks
.
(key, value) in expression
– where key
and value
can be any user defined identifiers,
and expression
is the scope expression giving the collection to enumerate.
For example: (name, age) in {'adam':10, 'amalie':12}
.
This example initializes the scope to a list of names and
then uses ngRepeat
to display every person: