ionic2 + angular2 - disable button on click

Basit picture Basit · Mar 2, 2016 · Viewed 6.9k times · Source

I have list of rows, and each one row has 2 more more buttons. I want to disable button on click event, so once its done ajax call then I can reenable it or hide it completely.

So I'm wondering how can I disable this single button on click event.

how can I disable from event?

<button [disabled]="buttonDisabled" (click)="trigger($event)">

trigger ($event)
{
  $event.buttonDisabled = true; // ?
}

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Mar 2, 2016
<div *ngfor="#row of rows">
  <button [disabled]="awaitingAjaxCall[row] ? true : null" (click)="trigger($event, row)">
</div>
rows: [0,1,2];
awaitingAjaxCall:boolean[] = [false, false, false];
trigger ($event, row)
{
  this.awaitingAjaxCall[row] = true;  
  this.http.get(...).map(...).subscribe(value => {
    this.value = value;
    // or here
    // this.awaitingAjaxCall[row] = false;
  }, error => {},
  () => this.awaitingAjaxCall[row] = false);
}