【问题标题】:How to call different function when toggling on and off in ion-toggle在离子切换中打开和关闭时如何调用不同的函数
【发布时间】:2018-09-17 06:42:59
【问题描述】:
当切换按钮“打开”时,请参阅下面的函数 buttonOn() 被调用,
我想在“关闭”时拨打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?
}
【问题讨论】:
标签:
typescript
ionic-framework
ionic2
ionic3
ion-toggle
【解决方案1】:
让我们用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?
}