2017-09-13 7 views
5

私は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(); 
    } 
+0

あなたは約束を返す必要があるようです。基本的に 'false'ではなく' return confirm.present(); 'を返します。 –

答えて

0

をあなたは、このための約束を必要としない、あなただけのtrueまたはfalseを返す必要がありますページに表示されるので、彼があなたのallowedToLeaveをtrueに設定し、あなたのページをポップアップさせるアラートの中でこれを残して確認したい場合は、ionViewCanLeaveを再度呼び出すでしょうが、今回はifステートメントを入力しません。

// About to leave 
    ionViewCanLeave() { 
    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.navCtrl.pop(); 
      }, 
     }, { 
      text: 'Cancel', 
      role: 'cancel' 
     }], 
     }); 
     confirm.present(); 
    }; 
    return true; 
    } 

これが役に立ちます。

関連する問題