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?
如果变量未定义,我正在尝试将类“扩展”设置为div。我试过这个,但没有成功。我究竟做错了什么?
{'expanded': typeof member != 'undefined'}
2 个解决方案
#1
11
You can do it easier:
你可以更容易地做到:
ng-class="{'expanded': member != undefined}"
or even:
ng-class="{'expanded': member }"
Example: http://plnkr.co/edit/9RMulfYViGKf91743VZz?p=preview
#2
2
Place your condition inside a function in the scope.
将您的条件放在范围内的函数中。
Plunkr: http://plnkr.co/edit/JnH0H7
#1
11
You can do it easier:
你可以更容易地做到:
ng-class="{'expanded': member != undefined}"
or even:
ng-class="{'expanded': member }"
Example: http://plnkr.co/edit/9RMulfYViGKf91743VZz?p=preview
#2
2
Place your condition inside a function in the scope.
将您的条件放在范围内的函数中。
Plunkr: http://plnkr.co/edit/JnH0H7