Search code examples
angularangular-materialangular-directive

setting mdButton attributes conditionally


As it is asked, I want to set button highlighted using accent color when it is active..

Something like

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

or perhaps something like

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

I seem to be able to do it that way in Angular 1, but doesn't have effect in Angular 2.

Can someone help?

Thank you


Solution

  • I think you have to set color same as below as color is @Input property as per documentation :

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