我需要写一个ng-switch
有4个条件的角度。
SO上的其他一些答案建议使用ng-if
而不是ng-switch
.
所以我尝试了ng-if
,但我真的不认为这是最好的方法,我会解释为什么:
基本上我需要显示 3 个不同的图标,这取决于我的范围内的一些变量。
我的模板中的代码如下:
<div class="buttons">
<div ng-if="test.mMode==4 && test.kit==4 && test.react.on==true && test.act==1">
<i class="icon ion-man"></i>
</div>
<div ng-if="test.mMode==4 && test.kit==4 && test.react.on==false && test.act==1">
<i class="icon ion-man"></i>
</div>
<div ng-if="zone.iActivity==1">
<i class="icon ion-man"></i>
</div>
</div>
现在,对我来说,这看起来真的很乱。而且,它没有按预期工作,因为它遍历所有打印所有真实的 if 语句。
是否可以做类似以下的事情?
<div class="buttons" ng-switch="test.act && test.Mode && test.kit && test.react.on">
<div ng-switch-when="1 && 4 && 4 && true">
<i class="icon ion-man"></i>
</div>
<div ng-switch-when="1 && 4 && 4 && false">
<i class="icon ion-man"></i>
</div>
<div ng-switch-when="1"> //I need only the first condition to be true, I don't need the others.
<i class="icon ion-man"></i>
</div>
</div>
或者,您对如何正确处理此类模板还有其他建议吗?
希望问题足够清楚。
谢谢你的帮助