我正在尝试将 ng-class 与 ng-repeat 一起使用,并尝试将一个类应用于我的第一个单元格。我的第一个单元格应该有红色背景。但是,它似乎没有任何效果。
<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;
}
这按预期工作(所有单元格都是红色的):
<td class="thing thing-red" ng-repeat="thing in things"></td>
最佳答案
试试下面的代码
<td class="thing" ng-repeat="thing in things" ng-class="{'thing-red': $index == 0}"></td>
关于javascript - 将 css 类应用于 ng-repeat 中的第一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44577843/