Question

Say I wanted to have an ng-class do two things:

1) populate a value from a variable like so

 `ng-class="myAwesomeJavaScriptVariable"`

and

2) conditionally set a predefined class:

  `ng-class = "{awesomeClass: myAwesomeBoolean}`

I am aware that I could do something like class="{{myAwesomeJavaScriptVariable}}" ng-class="{awesomeClass: myAwesomeBoolean}"

How (if this is even possible) could I amalgamate those two into a single ng-class expression?

Was it helpful?

Solution 2

@Abraham P:

To Set Both the Conditional Statement and Scope Variable as Class

ng-class="[{awesomeClass: myAwesomeBoolean},myAwesomeJavaScriptVariable]"

This Will Work Fine.

OTHER TIPS

I think it might be:

data-ng-class = "{ myAwesomeJavaScriptVariable, awesomeClass: myAwesomeBoolean }"

Alternatively:

   class = "{{ myAwesomeJavaScriptVariable}} left clearfix" data-ng-class="{awesomeClass: myAwesomeBoolean }"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top