将此多重条件转换为 ng-class 条件
convert this multiple condition into ng-class conditional
你好,我需要帮助将带有 'or' 的 'if-else' 条件转换为可在 ng-class.
中使用的条件
这是我的 ng-class 有条件,但它不能正常工作。
<span ng-class="{'green': work > toWork,
'red': work < toWork,
'black': work == toWork || overall == '-'}">
{{overall = showMonthly(work = (workers | getMonthValue: dts.value),
toWork = getMonthlyToWork(member.id, dts.value))}}
</span>
这是我要申请的条件:
if (work > toWork) {
return "green";
}else if (work < toWork) {
return "red";
}else if (work == toWork || overall == "-") {
return "black";
}
<span ng-class="{'green': work > toWork,
'red': work < toWork,
'black': (work == toWork || overall == '-')}">
...
</span>
检查这个。 (你的条件语句中缺少一个咒语)
编码愉快!
你不需要 ng-class,你只需要将逻辑放在 $scope
的方法中,如下所示
$scope.getClass = function(work, toWork, overall){
if (work == toWork || overall == "-"){
return "black";
}else if (work < toWork) {
return "red";
}else if(work > toWork) {
return "green";
}
}
在你看来,这样称呼它
<span class="{{getClass(work, toWork, overall)}}"></span>
你好,我需要帮助将带有 'or' 的 'if-else' 条件转换为可在 ng-class.
中使用的条件这是我的 ng-class 有条件,但它不能正常工作。
<span ng-class="{'green': work > toWork,
'red': work < toWork,
'black': work == toWork || overall == '-'}">
{{overall = showMonthly(work = (workers | getMonthValue: dts.value),
toWork = getMonthlyToWork(member.id, dts.value))}}
</span>
这是我要申请的条件:
if (work > toWork) {
return "green";
}else if (work < toWork) {
return "red";
}else if (work == toWork || overall == "-") {
return "black";
}
<span ng-class="{'green': work > toWork,
'red': work < toWork,
'black': (work == toWork || overall == '-')}">
...
</span>
检查这个。 (你的条件语句中缺少一个咒语)
编码愉快!
你不需要 ng-class,你只需要将逻辑放在 $scope
的方法中,如下所示
$scope.getClass = function(work, toWork, overall){
if (work == toWork || overall == "-"){
return "black";
}else if (work < toWork) {
return "red";
}else if(work > toWork) {
return "green";
}
}
在你看来,这样称呼它
<span class="{{getClass(work, toWork, overall)}}"></span>