私のホームページ内にregisterbackbuttonaction
をオーバーライドしました。unregistering
私のバックボタンアクションionViewDidLaave私のホームページから別のページにプッシュするとうまくいきます。モデルへの移動時またはサイドメニューから別のページに移動するときにデバイスのバックボタンの登録を解除する方法
問題:
私は、サイドメニューの項目については、私の
app.component.ts
ファイル内this.nav.push("pagename")
を書かれています。このため、私はデバイスの戻るボタンを押し過ぎた後、デバイスの戻るボタンをクリックして戻ることができません。私はアプリ全体からオーバーリディングバックボタン機能を削除すると、私は期待している出力を得ています。
また、
model
ページを開くと、ライフサイクルイベントが発生していない場合にも発生します。
は、ここで私は、それがバックボタンの登録を解除されたが、モデルとsidemenu部分は、それが動作していないプッシュしないとき
tsは上記のコードは正常に動作します
initializeBackButtonCustomHandler(){
let self = this
this.platform.ready().then(() => {
self.unregisterBackButtonAction = self.platform.registerBackButtonAction(() => {
if (this.menuCtrl.getOpen() != null) {
this.menuCtrl.close();
return
}else if(this.modal && this.modal.index === 0) {
console.log("invoking modal value")
/* closes modal */
// this.modal.dismiss();
this.viewCtrl.dismiss();
return
}
this.toast = this.toastCtrl.create({
message: "Press back again to exit the app",
position: 'bottom',
duration: 1500
});
this.toast.present();
this.clickCount = this.clickCount + 1;
this.toast.onDidDismiss(() => {
this.clickCount = 0;
})
if(this.clickCount == 2){
this.clickCount = 0;
this.toast.dismiss();
this.platform.exitApp();
}
}, 10)
});
}
ionViewDidEnter(){
this.initializeBackButtonCustomHandler();
}
ionViewDidLeave() {
this.unregisterBackButtonAction && this.unregisterBackButtonAction();
}
ファイル私のコードです。
私が登録を解除する必要がある理由は、すべてのページをハンドリングする必要がなく、あるページでregisterbackbuttonactionを実行した場合でも、残りのページに影響を及ぼしているためです。 –