Search code examples
angularjsng-class

How to set dynamic class name with complex statement in ng-class?


That's what I have:

ng-class="[{loading:loadingIsOn},{ color:true}]"

I have problem with color variable. It holds string value of defined color, but I can not pass it to HTML.

By the way,

 ng-class="color"

works fine.


Solution

  • If loadingIsOn is true, and color is 'green', and you want class="loading, green", then all you need is

    ng-class="[{loading:loadingIsOn}, color]"