如何在角度表达式中应用样式

时间:2018-04-16 10:32:14

标签: angularjs

我有以下代码行,其中有两个值Absent和Present。如果值为Absent,我想让它变成红色和粗体。我尝试过 通过应用风格,但它不起作用。请建议我如何做。

代码:

<div class="flex-2 bold1">{{attendance.status == 'Absent' ? "style='color:red;font-weight:bold'" :" "}}</div>

2 个答案:

答案 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'}”