我刚刚开始在我的项目中使用 Angular JS。
我一直在寻找一种方法来根据 Angular JS 表达式的值更改 HTML 表格单元格的背景颜色,但尚未找到解决方案。
这是单元格:
<td>{{data.material_or_service}</td>
欢迎任何帮助
你应该使用ng-class
: https://docs.angularjs.org/api/ng/directive/ngClass
Example:
css:
.red {
background-color: red;
}
.blue {
background-color: blue;
}
角度视图:
<td ng-class="{'red': (variable == 1), 'blue': (variable ==2)}">{{data.material_or_service}</td>
EDIT:
首先尝试一下:
<div ng-class="{'red' : (test != null)}">
hey !
</div>
<div ng-class="{'red' : (test == null)}">
hey 2 !
</div>
并设置.red { background-color: red; }
在CSS中。 Hey2 应该是红色的。
EDIT 2:
现在尝试:
<table>
<tr>
<td ng-class="{'red' : (test == null)}">
hey !
</td>
</tr>
</table>
The <td>
is red.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)