我需要在ng-style
中添加多個條件。 我該怎麼做?在ng樣式中添加多個條件
我嘗試了下面的代碼,但它不工作。
ng-style="ifTrue?'opacity:1;' : 'ifTrue? 'opacity: 1;': 'opacity: 0.5;''"
我需要在ng-style
中添加多個條件。 我該怎麼做?在ng樣式中添加多個條件
我嘗試了下面的代碼,但它不工作。
ng-style="ifTrue?'opacity:1;' : 'ifTrue? 'opacity: 1;': 'opacity: 0.5;''"
ng-style="ifTrue ? 'opacity:1;' : 'opacity: 0.5;'
ng-style=(condition) ? 'run this if true' : 'run this if false'
爲什麼不使用這樣的事情?
'ifTrue'只是一個符號,OP有多個條件。 –
您可以簡單地將您的條件與「,」分開。 事情是這樣的:
ng-style="{ 'background-color': '#ff0', color: 'red' }"
見這個例子:http://jsbin.com/fabisepede/edit?html,output
一定要記住把雙引號的 「虛」 字( '背景色')。
對於該值,您還可以使用您的控制器中定義的變量並有條件地指定樣式,但爲此我更喜歡ng-class。
您是否瞭解OP的問題? –
您可以使用類似
ng-style="condition && { /*properties*/ } || condition2 && { /*other properties*/ }"
相關:http://stackoverflow.com/questions/19375695/angular-ng-style-with-a-conditional-expression – 0aslam0