Search code examples
javascriptangularjsng-class

How to do IF/OR angular ng-class


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.


Solution

  • You can use the || operator like this.

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

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