我有以下代码行,其中有两个值Absent和Present。如果值为Absent,我想让它变成红色和粗体。我尝试过 通过应用风格,但它不起作用。请建议我如何做。
代码:
<div class="flex-2 bold1">{{attendance.status == 'Absent' ? "style='color:red;font-weight:bold'" :" "}}</div>
答案 0 :(得分:1)
有两种方法可以做到:
<div class="flex-2 bold1" ng-style="attendance.status == 'Absent' && {'color':'red','font-weight':'bold'}"></div>
其他是使用班级(推荐)
.highlighted {
color:red;
font-weight:bold
}
ng-class="{'highlighted': attendance.status == 'Absent'}"
答案 1 :(得分:0)
使用课程(推荐): 在类中创建样式并使用条件运算符
在ng-class中提及它ng-class =“{attendance.status =='缺席'?'测试':'test1'}”