Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS add two classes and one with conditional

I want to set an span 2 classes and one more with conditionality if item.qty is 0. I have this

<span ng-class="glyphicon,glyphicon-minus,{'notvisible': item.qty  0}"/>

But this dont work..i think this is not the sintax but i havent found anythink.

like image 465
colymore Avatar asked Jan 11 '23 23:01

colymore


1 Answers

Why don't you just add those static classes in the usual way and only leave the conditional in an ng-class, like this:

 <span class="glyphicon glyphicon-minus" ng-class="{'notvisible': item.qty==0}"/>

Also, you forgot the compare-operator == (I added it in the above example). If you only want to toggle the visibility of that element with the 'notvisible'-Class, I would even recommend you use the ng-show-Directive like this:

 <span ng-show="item.qty > 0" class="glyphicon glyphicon-minus" />
like image 116
David Losert Avatar answered Jan 13 '23 12:01

David Losert