javascript - 将 css 类应用于 ng-repeat 中的第一个单元格

标签 javascript html css angularjs

我正在尝试将 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/

相关文章:

html - CSS 媒体查询 - 不工作

html - 输入破坏了 Div 定位

javascript - Angular API 引用代码

javascript - 用对象数组中的另一个属性替换键值

javascript - 如何使用 node-js 使用聚合函数

html - 将容器外图像的左侧拉伸(stretch)到页面边缘

css - 如何最小化加载 Font Awesome 图标的延迟?

html - CSS 中的文件浏览器布局

css - 页面 anchor 和 CSS 转换(IE 和 Firefox 问题)

javascript - MySQL:使用 JSON 解析时,SUM(column) 始终返回 null