angularjs由三元,另外申请一个类总是 [英] angularjs apply one class by ternary and another always
问题描述
我想有'glyphicon类对我的图标标记始终。
我希望有'glyphicon加类时item.expanded是假的,glyphicon减类时item.expanded是真实的。
似乎有将是一个简单的方法来做到这一点,但我一直在使用三元运算符是不成功的,当我需要另一个类,以永远存在。下面code不起作用。
<我纳克级='glyphicon',(item.expanded)glyphicon减':'glyphicon加'>< / I>
纳克级真的不这样的表现。
谷歌表示:<一href=\"http://stackoverflow.com/questions/7792652/what-is-the-best-way-to-conditionally-apply-a-class-with-angularjs\">What是有条件地适用于一类angularjs的最佳方式?
所以你的问题的答案可能是:
&LT; I类=glyphiconNG-CLASS ={'glyphicon减':item.expanded,glyphicon加:item.expanded}&GT; &LT; I&GT /;
I want to have the 'glyphicon' class on my icon tag always. I want to have the 'glyphicon-plus' class when item.expanded is false, 'glyphicon-minus' class when item.expanded is true.
It seems there would be a simple way to do this but I've been unsuccessful using the ternary operator when I need another class to always be there. The following code does not work.
<i ng-class="'glyphicon', (item.expanded) ? 'glyphicon-minus' : 'glyphicon-plus'"></i>
ng-class don't really behave like this.
google says : What is the best way to conditionally apply a class with angularjs?
so an answer for your question could be :
<i class="glyphicon" ng-class="{'glyphicon-minus' : item.expanded, 'glyphicon-plus' : !item.expanded}"></i>
这篇关于angularjs由三元,另外申请一个类总是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!