AngularJS ng类if-else表达式 [英] AngularJS ng-class if-else expression
本文介绍了AngularJS ng类if-else表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用AngularJS
时,我通过以下方式使用ng-class
:
With AngularJS
I'm using ng-class
the following way:
<div class="bigIcon" data-ng-click="PickUp()"
ng-class="{first:'classA', second:'classB', third:'classC', fourth:'classC'}[call.State]"/>
我想知道是否可以使用if-else
表达式执行与此类似的操作:
I'm wondering if I can use the if-else
expression to do something similar to this:
<div class="bigIcon" data-ng-click="PickUp()"
ng-class="{first:'classA', second:'classB', else:'classC'}[call.State]"/>
因此,只要call.State
与first
或second
不同,请使用classC
并避免指定每个值?
So whenever call.State
differs from first
or second
use classC
and avoid specifying each value?
推荐答案
使用嵌套的嵌入式if-then语句( 例如:
<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 :)
这篇关于AngularJS ng类if-else表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<div ng-class="apt.name.length >= 15 ? 'col-md-12' : (apt.name.length >= 10 ? 'col-md-6' : 'col-md-4')">
...
</div>
查看全文