How do I know what the first item in the ngRepeat loop is?

1

How do I know what the first item in a ngRepeat loop is?

For example, I want to add a class to a div when it is the first of the loop.

Example:

<div ng-repeat="name in ['guilherme', 'wallace', 'bigown', 'rray']" ng-class="{'bold' : se_for_o_primeiro_do_loop}">
</div>
    
asked by anonymous 29.07.2016 / 16:53

1 answer

5

Use the $first variable. It is intended to indicate the first element in ng-repeat .

See:

<div ng-repeat="name in ['guilherme', 'wallace', 'bigown', 'rray']" ng-class="{'bold' : $first}"></div>

You can also use $last to indicate the last element in ng-repeat .

    
29.07.2016 / 16:57