0

当切换按钮为“on”时,请参见下面的函数buttonOn()被调用,
图1

我想在buttonOff()“关闭”时拨打电话,如下所示

在此处输入图像描述

.html

<ion-toggle (ionChange)="buttonOn()"></ion-toggle>

.ts

buttonOn() { 
    // this function is called;
}

buttonOff() {
   // how to call this function when toggle button gets off?
}
4

1 回答 1

5

让我们ngModel用来绑定你的toggle的状态,然后根据状态调用函数

.html

<ion-toggle [(ngModel)]="status" (ionChange)="onChange()"></ion-toggle>

.ts

status=true;
onChange(){
  if(this.status){
    this.buttonOn();
  }
  else{
    this.buttonOff()
  }
}

buttonOn() { 
    // this function is called;
}

buttonOff() {
   // how to call this function when toggle button gets off?
}
于 2018-04-07T10:34:03.073 回答