在 ng-class 中使用运算符(>,<,==,!=)

use of operators( >,<,==,!=) in ng-class

我想使用运算符检查值是否大于或等于 ng-class 中的其他数字或变量,然后相应地应用样式 class。基本上我想根据他们的概率给 div 上色。

ng-class的用法正确吗? 它打印

的值
{{1-apStats.preMappedProbability.toFixed(3)}} 

但是 ng-class 标签不起作用。有什么原因吗?

 <div ng-class="(1-apStats.preMappedProbability.toFixed(3) >=0.5) ? 'yellowClass':'redClass'"> {{1-apStats.preMappedProbability.toFixed(3)}} </div>

我做错了什么。?谢谢

<div ng-repeat="item in probability">
 <div ng-class="(1-item.prob.p)>=0.5 ? 'yellowClass':'redClass'">{{1-item.prob.p}} </div>

@Subhash

在 ng-class 指令中,首先你需要给出 class 名称然后条件如下 -

ng-class="{moreBtnGray : condition}"

在你的情况下——你应该使用两个 ng-class 并相应地保持状态。

 <div ng-class="{yellowClass: condition1, redClass:condition2}">{{1-prob.p}} </div>

语法:

<element ng-class="class : conditionExpression"></element>

这样修改了你的ng-class

<div ng-class="'yellowClass': 1-apStats.preMappedProbability.toFixed(3) >= 0.5; 'redClass' : anotherCondition">{{1-apStats.preMappedProbability.toFixed(3)}}</div>