ng-class="{'blue': item==1, 'blue': !item}"
如果我的项目未设置或项目等于1,但我无法以这种方式工作,我希望我可以上蓝色课。
blue if my item is not set or item equal to one
You need to use ||
operator and define expression as
ng-class="{'blue': !item || item==1 }"
You may find following code snippet helpful.
ng-class="{ 'active' : CreateCaseModel.CaseTypeId == 2 }
In above case, if expression is evaluated to true it will add active class.
replace "CreateCaseModel.CaseTypeId == 2" with your own condition, and it(expression) should return true or false.
ng-class="{ 'active' : expression }
For this to work just create one more class containing the same contents as in class blue and use that for second condition. Because ng-class
doesn't allow to same class to apply for different condition.
Contents of class blue and blue1 are same.
ng-class = "{'blue': item == 1, 'blue1': !item}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.