Close Modal in Ionic 4 by Back Button

后端 未结 6 2002
名媛妹妹
名媛妹妹 2021-02-03 12:38

I have a Modal in Ionic 4. I\'d like to close it, when a user press the back button on her mobile (or the bac

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 13:15

    For ionic 5 user

    this.platform.backButton.subscribeWithPriority(999, async() => {
        if (this.modalCtrl.getTop()) {
            const modal = await this.modalCtrl.getTop();
            console.log(modal)
            if (modal) { 
                this.modalCtrl.dismiss();
                return;
            } else {
                if (this.router.url=="/myrootpage" ) {
                navigator['app'].exitApp();
            } else {
                this.navCtrl.pop();
            }
        }
        } else {
            if (this.router.url=="/myrootpage") {
                navigator['app'].exitApp();
            } else {
                this.navCtrl.pop();
            }
        } 
    });
    

提交回复
热议问题