gpt4 book ai didi

javascript - ionic 3 : Close modal with phone's back button

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:59:21 34 4
gpt4 key购买 nike

我尝试在我的 Ionic 应用程序中覆盖手机的后退按钮。

如果我不在页面中,此代码允许我打开一个模式来关闭应用程序,否则关闭页面。

但这不允许我关闭打开的模式。如何检测我是否处于关闭模式?

platform.registerBackButtonAction(() => {

let nav = app.getActiveNav();
let activeView: ViewController = nav.getActive();
console.log(activeView);

if(activeView != null){
if(nav.canGoBack()) {
activeView.dismiss();
} else{
let alert = this.alertCtrl.create({
title: this.pdataManager.translate.get("close-app"),
message: this.pdataManager.translate.get("sure-want-leave"),
buttons: [
{
text: this.pdataManager.translate.get("no"),
handler: () => {
this.presentedAlert = false;
},
role: 'cancel',
},
{
text: this.pdataManager.translate.get("yes"),
handler: () => {
this.presentedAlert = false;
this.platform.exitApp();
}
}
]
});
if(!this.presentedAlert) {
alert.present();
this.presentedAlert = true;
}
}
}
});
}

最佳答案

1.导入IonicApp:

import {IonicApp } from 'ionic-angular';

2.添加到你的构造函数:

  private ionicApp: IonicApp

3.在您的platform.registerBackButtonAction 中添加:

let activeModal=this.ionicApp._modalPortal.getActive();
if(activeModal){
activePortal.dismiss();
return;
}

我在这里找到了答案: https://github.com/ionic-team/ionic/issues/6982

关于javascript - ionic 3 : Close modal with phone's back button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46662327/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com