Abraham P
Abraham P

Reputation: 15471

complex ng-class expression containing both a value and a conditional

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?

Upvotes: 0

Views: 955

Answers (2)

Samrat Saha
Samrat Saha

Reputation: 627

@Abraham P:

To Set Both the Conditional Statement and Scope Variable as Class

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

This Will Work Fine.

Upvotes: 2

Alex C
Alex C

Reputation: 1335

I think it might be:

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

Alternatively:

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

Upvotes: 3

Related Questions