单击后如何禁用按钮,使其仅单击一次?

时间:2019-12-24 10:37:58

标签: angular

我正在使用Angular8。我有两个按钮punchInpunchOut。单击punchIn按钮后,将不得不禁用它。怎么做?

2 个答案:

答案 0 :(得分:1)

在component.ts文件中,创建一个变量setDisable。单击按钮插入。将此变量的值更改为true

export class AppComponent  {
    setDisable = false;

    punchIn() {
     this.setDisable = true;
    }
}

您的按钮HTML

<button [disabled]="setDisable" (click)="punchIn()">Puch in</button>

答案 1 :(得分:0)

在您的组件ts中:-

export class AppComponent  {
    isPunchInDisable = false;
    isPunchOutDisable = false;

    punchIn() {
     this.isPunchInDisable = true;
    }
    punchOut() {
     this.isPunchOutDisable = true;
    }
}

在您的HTML中:-

<button [disabled]="isPunchInDisable " (click)="punchIn()">Puch in</button>
<button [disabled]="isPunchOutDisable " (click)="punchOut()">Puch Out</button>

基本上,isPunchInDisableisPunchOutDisable变量保持禁用按钮的状态