2017-07-26 147 views
0

我正在使用Ionic和FCM(firebase)插件發送推送通知。我可以收到通知,當我點擊通知時,它會成功觸發警報,但不會導航到指定的選項卡。只是爲了確保這條線:點擊通知後,Ionic無法導航到特定選項卡?

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

您應該使用箭頭功能

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屬性存在。

+1

非常感謝!那工作:D – Mikethetechy

相關問題