防止翻页按钮,Ionic2在特定条件下

防止翻页按钮,Ionic2在特定条件下,ionic2,Ionic2,我用的是ionic2。 我有几个页面和流程-P1->P2->P3 我想在P3上使用ionViewCanLeave(),这样,如果不满足某些条件,当用户按下后退按钮时,它应该发出警报 this.navCtrl.pop() .catch(() => { console.log('should I stay or should I go now'); }); ionViewCanLeave(): boolean{ // here we can either return

我用的是ionic2。 我有几个页面和流程-P1->P2->P3

我想在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;
    }
}

但这是一个错误。

我认为你做错了。。。此函数
ionViewCanLeave
在休假时运行,因此此时您应该检查是否可行。希望这能帮助你

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

  if(percentMarks > 0){
    this.navCtrl.pop();
  } else {
    console.log('i should stay'));
  }

它给出了什么错误?