2017-04-19 5 views
-1

私はionic2を使用しています。 私はページ数が少なく、フローP1→P2→P3です。特定の条件のページ戻るボタン、Ionic2を防ぐ

P3にionViewCanLeave()を使用したいので、特定の条件が満たされない場合、ユーザーが戻るボタンを押したときに警告が表示されます。

this.navCtrl.pop() 
    .catch(() => { 
    console.log('should I stay or should I go now'); 
    }); 

ionViewCanLeave(): boolean{ 
    // here we can either return true or false 
    // depending on if we want to leave this view 
    let percentMarks = Math.floor((this.totalCorrectAnswers/this.questionSetChosen.length) * 100); 
    if(percentMarks > 0){ 
     return true; 
    } else { 
     return false; 
    } 
} 

ただし、エラーが発生しています。

+0

どのようなエラーがありますか? –

答えて

0

私はあなたが間違っていると思います...この機能ionViewCanLeaveは、その時点で可能であるかどうかを確認する必要があります。これがあなたを助けることを願っています。

ionViewCanLeave() { 
    let percentMarks = Math.floor((this.totalCorrectAnswers/
        this.questionSetChosen.length) * 100); 

    if(percentMarks > 0){ 
    this.navCtrl.pop(); 
    } else { 
    console.log('i should stay')); 
    } 
関連する問題