Search code examples
angularjsng-class

Multiple values in ngClass


I have a controller which gives me the right value for my actions. The possible values are 1, 2, 3, 4. I have checked this and works fine. I created a class, which will only be active when the value is 1. This works perfectly. But i like to class not only to be set for the value 1, but also for 3 and 4. I thought this would be pretty easy, but i cannot figure it out. I post my current expression, and what i tried. Hopefully one of you can help me.

Works fine, also if i change 1 to 3 (but ofcourse it reacts only on 3 then)

ng-class="{thumbdarken: thumb.isSet(1)}"

This is what i would like to have working

ng-class="{thumbdarken: thumb.isSet(1 || 3 || 4)}"

Thanks in advance...


Solution

  • You should probably make three function calls each with different parameter, rather than a single function call (because 1 || 3 || 4 will always evaluate to 1, meaning you'd be always checking for thumb.isSet(1)). So, do something like this:

    ng-class="{thumbdarken: ( thumb.isSet(1) || thumb.isSet(3) || thumb.isSet(4) )}"