Abraham P Abraham P - 1 year ago 113
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



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 Source

@Abraham P:

To Set Both the Conditional Statement and Scope Variable as Class

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

This Will Work Fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download