Abraham P Abraham P - 3 months ago 29
AngularJS Question

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?

Answer

@Abraham P:

To Set Both the Conditional Statement and Scope Variable as Class

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

This Will Work Fine.