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

时间:2017-05-02 15:43:01

标签: angular angular-directive angular-template

我正在尝试!点击另一个按钮时单击按钮,但无法使其工作...

这是我的代码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;
    }
  }

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

尝试使用[attr.disabled]

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

答案 1 :(得分:0)

我设法解决自己的问题lol

这就是我所做的:

在我的TS类课程中,我更改了&#34; isButtonToggled&#34;功能如下:

DateTime nightTimeStart = new DateTime(1, 1, 1, 23, 0, 0);
DateTime nightTimeEnd = new DateTime(1, 1, 2, 6, 0, 0);

if (shift.UntilTime < nightTimeStart || shift.FromTime > nightTimeEnd)
    return 0;
else if (shift.UntilTime <= nightTimeEnd && shift.FromTime >= nightTimeStart)
    return (decimal)(shift.UntilTime - shift.FromTime).TotalHours;
else if (shift.UntilTime > nightTimeEnd && shift.FromTime < nightTimeStart)
    return (decimal)(nightTimeEnd - nightTimeStart).TotalHours;
else if (shift.UntilTime < nightTimeEnd && shift.FromTime < nightTimeStart)
    return (decimal)(nightTimeEnd - shift.FromTime).TotalHours;
else
    return (decimal)(shift.UntilTime - nightTimeStart).TotalHours;

}