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'}
You can use both class and ngClass as the first one gives you the opportunity to apply a class that you want to implement in all cases under any circumstances and the later to apply classes conditionally.
ngClass is more powerful. It allows you to bind a string of classes, an array of strings, or an object like in your example. attr. foo is for binding to attributes instead of properties.
ngClass is a directive in Angular that adds and removes CSS classes on an HTML element.
You can do it easier:
ng-class="{'expanded': member != undefined}"
or even:
ng-class="{'expanded': member }"
Example: http://plnkr.co/edit/9RMulfYViGKf91743VZz?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With