$first in ngRepeat

Diolor picture Diolor · Oct 28, 2013 · Viewed 84.7k times · Source

I have an array $scope.items.

I want if the item is the $first one of the ngRepeat to add the css class in.

Is it something that can be done with angular? Generally how can I handle the booleans in Ajs?

<div ng-repeat="item in items">
   <div class='' > {{item.title}}</div>
</div>

Answer

Chandermani picture Chandermani · Oct 28, 2013

It should be

<div ng-repeat="item in items">
   <div ng-class='{in:$first}' > {{item.title}}</div>
</div>

Look at ng-class directive in http://docs.angularjs.org/api/ng.directive:ngClass and in this thread What is the best way to conditionally apply a class?