Question

If I have:

ng-class='{in:$first}'

What is the simplest way to make it add the in class when $first is true or if let's say the item.in ($scope.item.in) value is true ?


note: $first is because I have a ng-repeat enclosing this line but it can be any other boolean or 0/1 value if you feel the code is incomplete.

Was it helpful?

Solution

You can use the || operator like this.

<div ng-class="{ in: $first || item.in }"> Test </div>

Example: http://jsfiddle.net/eLPE8/

OTHER TIPS

you can use the or operator in ng-class as such

ng-class="{myclass: condition1 || condition2}"

your element will gain the myclass class if condition1 or condition2 is true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top