ngRepeat directive

The ngRepeat directive is really useful to iterate over arrays and objects. It can be used with any kind of element such as the rows of a table, the elements of a list, and even the options of select.

We must provide a special repeat expression that describes the array to iterate over the variable that will hold each item in the iteration. The most basic expression format allows us to iterate over an array, attributing each element to a variable:

Variable in array
It's also possible to use a slightly different expression to iterate over objects: (key, value) in object
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>

<tr ng-repeat = "x in employees">
<td>{{ x.name }}</td>
<td>{{ x.age }}</td>
</tr>
</table>

Beyond iterating, we can identify which is the first or the last element, what is its index number, and many other things. This can be achieved by using the following properties:

VariableTypeDetails
$indexNumberNumber of the element
$firstBooleanThis is true if the element is the first one
$lastBooleanThis is true if the element is the last one
$middleBooleanThis is true if the element is in the middle
$evenBooleanThis is true if the element is even
$oddBooleanThis is true if the element is odd
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +