我需要在我的ngClass中同时使用表达式和值:
表达式为:ngClass="{'ns-show' : notif.isActive, 'ns-hide' : !notif.isActive}"
值应该是:'ngClass="[notif.]类型,notif.effect] "
这里notif.type
和notif.effect
包含一个类的名称,例如ns-growl
。
我尝试ngClass="{'ns-show' : notif.isActive, 'ns-hide' : !notif.isActive}[notif.type, notif.effect]"
,但我得到一个错误:
Syntax Error: Token ',' is unexpected, expecting []] at column 50 of the expression
正确的语法是什么?
您可以对表达式使用简单的绑定,并为您的映射保留ng-class,这将组合您的类:
<div class="{{notif.type}} {{notif.effect}}" ng-class="{'ns-show' : notif.isActive, 'ns-hide' : !notif.isActive}">
编辑:因为Angular没有'ng-show'类,我回到我原来的答案
ng-class="{ng-show:notif.isActive, ng-hide:notif.isActive, notif.effect:ture, notif.type:true}"
砰砰作响
另一个可行的解决方案是
ng-hide="!notif.isActive" ng-class="[ng-show, notif.type, notif.efect]"