【发布时间】:2019-08-24 13:38:47
【问题描述】:
更新
<div style="margin-top: 10px; color: white; height: 50%; padding: 5%; font-size: 25px; font-weight: bold"
[ngStyle]="{'background-color': global.timeSpent <= '10' ? 'LimeGreen' : ((global.timeSpent > '10' && global.timeSpent <= '20') ? 'Gold' : 'Red' ) }">{{global.timeSpent}}</div>
二次接近
<div [ngStyle]="styleColor"> {{global.timeSpent}}</div>
styleColor(){
this.global.timeSpentToStoryPointVariance = this.global.timeSpentToStoryPointVariance.split('%')[0]
if(this.global.timeSpentToStoryPointVariance <= '10') {
return '{ "background-color": "LimeGreen" }';
}
else if(this.global.timeSpentToStoryPointVariance > '10' && this.global.timeSpentToStoryPointVariance <= '20'){
return '{ "background-color": "Gold"}';
}
else{
return '{ "background-color": "Crimson" }';
}
}
条件无法正常工作。我认为 '' 运算符无法正常工作,因为 IDE 显示 标志为红色,其余为蓝色,甚至 > 标志也为蓝色。
这里有什么问题?
【问题讨论】:
-
ngStyle是一个元素的角度attribute -
检查更新的答案
-
你的意思是更新的问题
-
顺便问一下,是什么让您将
<=与string一起使用? -
它应该可以工作了:)