私はIonic 2を使用しています。私は、離れて移動するときに離れることを確認するようにユーザーに指示する必要があります(ビデオはその時に再生されています。Ionicのタブの変更にナビガードを使用するにはどうすればよいですか?
ユーザーは、次のコードを使用して、トップナビゲーションバーの[戻る]ボタン、またはバックハードウェアボタン(アンドロイド)をクリックしたときに、私はこのために正常に動作しています
// About to leave
ionViewCanLeave() {
this.api.getDefaultMedia().pause();
return new Promise((resolve, reject) => {
if(!this.allowedToLeave) {
let confirm = this.alertCtrl.create({
title: 'Are you sure?',
message: 'If you leave a class you will need to start over. Are you sure you want to leave? If you need a break you can pause by tapping the video.',
buttons: [{
text: 'OK',
handler:() => {
this.allowedToLeave = true;
resolve();
},
}, {
text: 'Cancel',
handler:() => {
reject();
}
}],
});
confirm.present();
}
});
}
ビューがタブに座っています。別のタブをクリックするとにはが呼び出されないので、ユーザーにはメッセージは表示されず、タブだけが切り替わります。
このプロンプトをタブの変更にも表示するにはどうすればよいですか?このビューはルートタブページではありません。
-
私はは、タブの変更にと呼ばれる、ionViewWillLeave()
を使用して試してみましたが、それは切り替えからユーザーを防ぐ方法を許可していません。以下のコードプロンプトを示していますが、タブが変更された後:ユーザーが去ることができる場合
// Called when user exits page via tab
ionViewWillLeave() {
this.api.getDefaultMedia().pause();
if(!this.allowedToLeave) {
let confirm = this.alertCtrl.create({
title: 'Are you sure?',
message: 'If you leave a class you will need to start over. Are you sure you want to leave? If you need a break you can pause by tapping the video.',
buttons: [{
text: 'OK',
handler:() => {
this.allowedToLeave = true;
this.leave();
},
}, {
text: 'Cancel',
handler:() => {
// Do nothing
}
}],
});
confirm.present();
return false;
}
}
// Leave the view
leave() {
this.navCtrl.pop();
}
あなたは約束を返す必要があるようです。基本的に 'false'ではなく' return confirm.present(); 'を返します。 –