I have two parameters I'm trying to check to set a class with ng-class, but for some reason it will only work with one.
Here is my code:
ng-class="{'alert-viewed':item.viewed && item.status <= 0}
If is just us 'alert-viewed':item.viewed it works. But adding on the item.status check breaks it.
Anyone see what I'm missing?
The order of operations is wrong in your expression. Because &&
has a higher precedence than <=
, your flags are being evaluated first, then compared to <=0
. Instead, you want the second half of your expression to be evaluated first, and then evaluated against the first half, which means you need parenthesis around the second half of the statement.
ng-class="{'alert-viewed':item.viewed && (item.status <= 0)}