角纳克级的if-else前pression [英] angular ng-class if-else expression
本文介绍了角纳克级的if-else前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用angularjs纳克级:
< DIV CLASS =bigIcon数据-NG-点击=皮卡()
NG-CLASS ={第一次:'CLASSA,第二:CLASSB',第三:'classC,第四名:classC'} [call.State]/>
和我想知道,如果如果其他前pression,我可以做类似这样的东西,我可以用:
< DIV CLASS =bigIcon数据-NG-点击=皮卡()
NG-CLASS ={第一次:'CLASSA,第二:CLASSB',否则:classC'} [call.State]/>
这意味着每当 call.State
从第一
或第二$ C $不同C>使用
classC
,而不是指定的每个值。
谢谢!
解决方案
使用嵌套内联的if-then语句(的三元操作符 的)
< DIV纳克级=...1类:(...'二类':'类-3')?>
例如:
< DIV纳克级=apt.name.length> = 15'COL-MD-12'?:?(apt.name.length> = 10'山口-MD-6':'COL-MD-4')>
...
< / DIV>
和确保它的可读的同事:)
I'm using angularjs ng-class at the following way:
<div class="bigIcon" data-ng-click="PickUp()"
ng-class="{first:'classA', second:'classB', third:'classC', fourth:'classC'}[call.State]"/>
and I wondered if I can use if-else expression, can I do something similar to this:
<div class="bigIcon" data-ng-click="PickUp()"
ng-class="{first:'classA', second:'classB', else:'classC'}[call.State]"/>
meaning whenever call.State
different from first
or second
use classC
and not specify each value.
thanks!
解决方案
Use nested inline if-then statements (Ternary Operators)
<div ng-class=" ... ? 'class-1' : ( ... ? 'class-2' : 'class-3')">
for example :
<div ng-class="apt.name.length >= 15 ? 'col-md-12' : (apt.name.length >= 10 ? 'col-md-6' : 'col-md-4')">
...
</div>
And make sure it's readable by your colleagues :)
这篇关于角纳克级的if-else前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文