Prabhu
Prabhu

Reputation: 13335

Apply css class to the first cell in ng-repeat

I am trying to use ng-class with ng-repeat, and trying to apply a class to my first cell. My first cell should have a red background. However, it doesn't seem to have any effect.

<table>
    <tbody>
       <tr ng-repeat="item in items" class="item">
           <td class="thing" ng-repeat="thing in things" ng-class="{thing-red: $first}"></td>
        </tr>
     </tbody>
 </table>

.thing-red {
    background:red;
}

This works as expected (all cells are red):

<td class="thing thing-red" ng-repeat="thing in things"></td>

Upvotes: 0

Views: 46

Answers (1)

Yeshwanth
Yeshwanth

Reputation: 70

Try below code

<td class="thing" ng-repeat="thing in things" ng-class="{'thing-red': $index == 0}"></td>

Upvotes: 1

Related Questions