【发布时间】:2018-11-05 13:09:29
【问题描述】:
我的任务是向一个元素添加几个类,其中一个必须是有条件的。我查看了文档,发现了这个:
<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
但问题是另一个类必须有一个来自变量的动态名称,我想做这样的事情:
[ngClass]="{
[menuItem.class]: true,
'open': router.url.split('/')[1] === menuItem.path
}">
我得到了这个错误
Unexpected token [, expected identifier, keyword, or string
任何想法如何实现我想要的?
【问题讨论】:
标签: angular angular-directive ng-class