question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set button type dynamicaly

See original GitHub issue

Please describe the feature you would like to request.

I’m using MatButton directive as attribute like this: <button mat-button buttonType="{{button.type}}></button>" I want to change ‘mat-button’ directive according to ‘button.type’, for example if ‘button.type’ is ‘stroked’ then ‘mat-button’ changed to ‘mat-stroked-button’. How can to change type of button dynamicaly?

What is the use-case or motivation for this proposal?

Is there anything else we should know?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:23
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

20reactions
maxdonetskcommented, Jul 14, 2020

<button mat-button [ngClass]="condition ? 'mat-raised-button' : 'mat-stroked-button'">Button</button> You can also use ‘mat-flat-button’ instead of ‘mat-raised-button’ if you don’t need extra styling such as shadow.

9reactions
intellixcommented, Mar 26, 2019

I’m using a CMS to allow adding buttons dynamically and for the button.type I’m doing something like this:

export interface Button {
  id: string;
  text: string;
  type: string;
  color: string;
  routerLink: string;
}
<ng-container [ngSwitch]="data.type">
  <a *ngSwitchDefault mat-button [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'raised'" mat-raised-button [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'stroked'" mat-stroked-button [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'flat'" mat-flat-button [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'icon'" mat-icon-button [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'fab'" mat-fab [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
  <a *ngSwitchCase="'mini-fab'" mat-mini-fab [color]="data.color" [routerLink]="data.routerLink">{{ data.text }}</a>
</ng-container>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material bind button type dynamically - Stack Overflow
I'm using Angular Material in my project. I want to set the button type dynamically based on a variable ...
Read more >
Alpha Anywhere | Change Button Text Dynamically
The contents of a button can be dynamically set at run-time using JavaScript.
Read more >
Dynamic button configuration in iOS 15 - Sarunw
We will learn how to change button configuration based on the internal changes, e.g., highlighted and selected, and external changes, e.g., your ...
Read more >
Dynamic Handling of buttons in Tkinter - Plus2net
Creating buttons dynamically ... We can set a variable to any integer and based on this value , number of buttons will be...
Read more >
Create dynamic HTML button element with JavaScript/jQuery
In vanilla JavaScript, you can use the document.createElement() method to programmatically create an HTML button element and set its required attributes. Then ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found