I am using angular material and ngx-form-schema in an angular 7 project. How can create a directive to handle all type of mat buttons? I want to send type of mat button such 'mat-flat-button' or 'mat-raised-button' to that directive then the directive show that mat button.
1 Answer
Create two buttons. One with mat-flat-button, one with mat-raised-button. Then use *ngIf or ngSwitch to display only one at a time.
2 Comments
Mostafa Farhani
This may more than two button type needed. Is there generic method?
Dániel Barta
One way is to create a wrapper component which takes the type as an input, and in that component you use
ngSwitch. A fancier solution would be to use ng-container and you can bind the type to the ngComponentOutlet attribute. If I'm correct, this way it also gets the component factories dynamically.