Javascript Can';t将布尔值返回到ionViewCanLeave
当用户想要离开当前页面时,我必须显示我的定制警报(由modal设计)。它会提示“是”或“否”按钮。如果用户点击yes,我想返回false(即不应该离开页面)。如果用户单击否,我希望返回true(即离开页面) 我尝试了很多解决方案,但都没有任何帮助Javascript Can';t将布尔值返回到ionViewCanLeave,javascript,angular,typescript,ionic-framework,Javascript,Angular,Typescript,Ionic Framework,当用户想要离开当前页面时,我必须显示我的定制警报(由modal设计)。它会提示“是”或“否”按钮。如果用户点击yes,我想返回false(即不应该离开页面)。如果用户单击否,我希望返回true(即离开页面) 我尝试了很多解决方案,但都没有任何帮助 ionViewCanLeave(): boolean { if (this.operationMode == undefined) { if (this.cycleMode == "AA") { if ( this.orofic
ionViewCanLeave(): boolean {
if (this.operationMode == undefined) {
if (this.cycleMode == "AA") {
if (
this.oroficeLevel != this.oroficeLevelInitial ||
this.name != this.nameInitial ||
this.scheduleMode != this.scheduleModeInitial
) {
let modal = this.modalCtrl.create(AlertPage, {
message: "Save Changes?"
});
modal.onDidDismiss(data => {
if (data == "yes") {
return false;
} else {
return true;
}
});
modal.present();
}
} else if (this.cycleMode == "CC") {
if (
this.oroficeLevel != this.oroficeLevelInitial ||
this.name != this.nameInitial ||
this.scheduleMode != this.scheduleModeInitial
) {
let modal = this.modalCtrl.create(AlertPage, {
message: "Save Changes?"
});
modal.onDidDismiss(data => {
if (data == "yes") {
return false;
} else {
return true;
}
});
modal.present();
}
}
}
}
这段代码出了什么问题?@Random,return语句在modal dismise处理程序中。因此,这不是ionViewCanLeave()的范围,我不知道ionic,但有时您可以在此类方法中提供承诺,而不是布尔值。如果有返回“退出”承诺的方法,请查看模式文档。。。如果是这样,您可以执行“return modal.exitPromise”