Search code examples
angularangular-template

How to disable a particular button in Angular 7


I'm going to disable a particular button from a bunch of buttons as below:

<button name="paybtn-1" id="paybtn-1" (click)="myfunc(1)">Pay</button>
<button name="paybtn-2" id="paybtn-2" (click)="myfunc(2)">Pay</button>
<button name="paybtn-3" id="paybtn-3" (click)="myfunc(3)">Pay</button>

Say, I want to disable paybtn-1 when it clicked.

In the ts file, I pass the id of the button however, I stuck how can disable the particular button:

myfunc(id){
//
}

Solution

  • If You need to do this in proper way, have an array defined in your TS for each button and bind disalbed property to the button. Change it to false when clicking on the button.