lakshay lakshay - 6 months ago 63
AngularJS Question

how to write conditional statements in ng-class?

I have written the condition as

ng-class="{true: 'ion-ios-heart', false: 'ion-ios-heart-outline'}[favOffers[]]"

i.e if favOffers[] has a value then apply the class in true statement else apply the class in false statement.

But it is not working. favOffers is defined in my controller.


You can simply use a ternary condition in your case

<div ng-class="favOffers[] ? 'ion-ios-heart': 'ion-ios-heart-outline'"></div>