I am new at Angular, and I would like to know how to disable a button after I click that same button and performed the action correspondent
This is my button html code
<button type="button" class="btn btn-primary" (click)="actionMethod()">Give Kitchen access</button> <br> <br>
You can bind the disabled
property to a flag (e.g. clicked
), and set the flag in the click
event handler:
<button type="button" [disabled]="clicked" (click)="actionMethod(); clicked = true;" class="btn btn-primary">Give Kitchen access</button>
The flag should be declared in the component class:
clicked = false;
See this stackblitz for a demo.
<button type="button" class="btn btn-primary" (click)="actionMethod($event)">Give Kitchen access</button>
actionMethod(event: any) {
event.target.disabled = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With