2

I want to add material button directive to button element. But there are several types of button, how to set angular material2 directive according to button type? The code is:

<button mat-buttton color="{{button.color}}" buttonType="{{button.type}}"></button>

That mat-button is an angular material2 directive to set some effects for button. For example when button.type is 'stroked' mat-button should be change to mat-stroked-button or if button.type is 'flat' mat-button should be change to mat-flat-button.

Mostafa Farhani
  • 305
  • 2
  • 16
  • 1
    please post some code with what you have tried so far – emvidi Mar 02 '19 at 13:47
  • I am trying to change mat-button if button.type changed dynamicaly in ts file – Mostafa Farhani Mar 02 '19 at 14:06
  • 1
    you mean changing the button type? attr.type="{{buttonType}}" – emvidi Mar 02 '19 at 14:21
  • mat-button is a directive that makes some effects on button, I want change this directive dynamically when type of button changed. For example if button.type is 'stroked' then replace mat-button with mat-stroked-button or button.type is 'flat' then replace mat-button with mat-flat-button. There are all types of material buttons in https://stackblitz.com/angular/kbldyyeplld?file=app%2Fbutton-types-example.html – Mostafa Farhani Mar 02 '19 at 14:28
  • 1
    ok, now is clear what you want to do. Never did it, but in early version was not possible, check [this question](https://stackoverflow.com/questions/42605871/how-to-change-directive-dynamically-in-angular-2) – emvidi Mar 02 '19 at 14:35

0 Answers0