如何在单击一个按钮时单击另一个按钮 angular 2?

How to !click one button when another is clicked angular 2?

我正在尝试 !click on button while another is clicked,但还不能让它工作...

这是我的代码 HTML:

 <ion-row class="rowconfig">
<ion-col class="colconfig">
  <button ion-button clear small block [color]="!buttonClicked1 ? 'gray' : 'white'" (click)="isButtonToggle(1)">100 Enviadas</button>
</ion-col>
<ion-col>
  <button ion-button clear small block [color]="!buttonClicked2 ? 'gray' : 'white'" (click)="isButtonToggle(2)">50 Recebidas</button>
</ion-col>

和 TS:

 isButtonToggle(x):void{
    switch(x){
      case 1:
        this.buttonClicked1 = !this.buttonClicked1;
        break;
      case 2:
        this.buttonClicked2 = !this.buttonClicked2;
        break;
    }
  }

感谢您的帮助!

尝试使用 [attr.disabled]:

<button ion-button clear small block [color]="!buttonClicked1 ? 'gray' : 'white'" (click)="isButtonToggle(1)" [attr.disabled]="!buttonClicked1  ? true : null">100 Enviadas</button>

我设法解决了我自己的问题哈哈

这就是我所做的:

在我的页面 TS class 中,我将 "isButtonToggled" 函数更改为:

isButtonToggle(x):void{
switch(x){
  case 1:
    this.buttonClicked1 = !this.buttonClicked1  
    if(this.buttonClicked2 = true){
        this.buttonClicked2 = !this.buttonClicked2;
    }
    break;
  case 2:
    this.buttonClicked2 = !this.buttonClicked2;
    if (this.buttonClicked1 = true){
        this.buttonClicked1 = !this.buttonClicked1;
    }
    break;
}

}