单击通知后,Ionic无法导航到特定选项卡?

时间:2017-07-26 02:35:23

标签: ionic-framework notifications ionic3

我正在使用Ionic和FCM(firebase)插件发送推送通知。我可以收到通知,当我点击通知时它会成功触发警报,但它不会导航到指定的选项卡。只是为了确定这一行:

this.tab.select(2);

我已经测试过使用按钮导航该代码并且可以正常工作

      FCMPlugin.onNotification(function(data){
    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.

     alert('data was tapped');
        this.tab.select(2);
          //this.navCtrl.push(ViewurgentnewsPage); also tried this

    }else{
      //Notification was received in foreground. Maybe the user needs to be notified.

        alert('this was received on foreground');


    }
    });

1 个答案:

答案 0 :(得分:1)

您应该使用箭头功能

  FCMPlugin.onNotification((data) => {
    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.
      alert('data was tapped');
      this.tab.select(2);
    } else {
      //Notification was received in foreground. Maybe the user needs to be notified.
      alert('this was received on foreground');
    }
  });

通过使用箭头函数,this关键字仍然引用了this.tab属性所在的组件代码。