Himmators
Himmators

Reputation: 15036

Set class in angular if variable is defined?

I'm trying to set the class "expanded" to a div if the variable is undefined. I attempted this, but had no success. What am I doing wrong?

{'expanded': typeof member != 'undefined'}

Upvotes: 5

Views: 9564

Answers (2)

Anders Bornholm
Anders Bornholm

Reputation: 1336

Place your condition inside a function in the scope.

Plunkr: http://plnkr.co/edit/JnH0H7

Upvotes: 2

Ivan Chernykh
Ivan Chernykh

Reputation: 42196

You can do it easier:

 ng-class="{'expanded':  member != undefined}"

or even:

ng-class="{'expanded':  member }"

Example: http://plnkr.co/edit/9RMulfYViGKf91743VZz?p=preview

Upvotes: 11

Related Questions