有条件地设置 mdButton 属性

Posted

技术标签:

【中文标题】有条件地设置 mdButton 属性【英文标题】:setting mdButton attributes conditionally 【发布时间】:2017-05-28 11:30:38 【问题描述】:

按照要求,我想在按钮处于活动状态时设置使用强调色突出显示的按钮..

有点像

<button md-button *ngFor="let item of items" [attr.color]="item.caption == activeItem ? 'accent' : ''">

或者类似的东西

<button md-button *ngFor="let item of items" color=" item.activeColor "

我似乎可以在 Angular 1 中这样做,但在 Angular 2 中没有效果。

有人可以帮忙吗?

谢谢

【问题讨论】:

【参考方案1】:

我认为您必须将color 设置为与以下相同,因为color@Input 属性,根据documentation :

<button md-button *ngFor="let item of items" [color]="item.caption ==  activeItem ? 'accent' : ''">

【讨论】:

以上是关于有条件地设置 mdButton 属性的主要内容,如果未能解决你的问题,请参考以下文章