Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-class multiple conditions with OR operator

Tags:

I try to find out the good syntax for adding classes depending on angular values. I want to activate a class regarding 2 conditions (one on live user changes, and one on loading datas) with a OR operator.

Here is the line :

 <a href="" ng-click="addFavorite(myfav.id);favorite=!favorite">     <i class="fa orange" ng-class="{'fa-star': (favorite || (fav==myfav.id)), 'fa-star-o': !favorite}"></i>  </a> 

I tried some different codes like this one :

 ng-class="{'fa-star': favorite, 'fa-star': (fav==myfav.id), 'fa-star-o': !favorite}" 

without any success. Can someone help me finding the good syntax ?

like image 963
user1713964 Avatar asked Jun 18 '14 14:06

user1713964


1 Answers

Try this.

<a href="" ng-click="addFavorite(myfav.id);favorite=!favorite">  <i class="fa orange" ng-class="{'fa-star': favorite || fav==myfav.id, 'fa-star-o': !favorite}"></i> 

No need the brackets.

like image 101
Abhilash Augustine Avatar answered Oct 16 '22 15:10

Abhilash Augustine