2017-04-20 43 views
0

我使用这个插件https://github.com/phonegap/phonegap-plugin-push取得Ionic2应用程序,并发出通知。当用户收到通知时,根据其数据,我希望他们相应地移动页面。Ionic2推送通知页面移动

我送routeadditionalData区分来引导他们的页面。除此之外,我想引导用户访问该页面的特定标签。

任何建议或意见,将不胜感激!

预先感谢您。

app.components.ts

declare var TabIndex: any; 

..... 

push.on('notification').subscribe((notification:any) => { 
    if (notification.additionalData.route == 'order-list') { 
     console.log('order-list is selected'); 
     //WHAT DO I DO? 
     //I want the user to move to TabsPage(parent view) and its second-tab(child view) 
    } else if (notification.additionalData.route == 'personal') { 
     console.log('personal is selected'); 
     //I want the user to move to TabsPage and its third-tab 
    } 
}); 

EDITED:

app.components.ts

push.on('notification').subscribe((notification:any) => { 
    if (notification.additionalData.AppRoute == 'order-list') { 
     console.log('move to orderlist'); 
     // this.nav.push(TabsPage, {"index" : 1}); 
     TabIndex = 1; 
    } else if (notification.additionalData.AppRoute == 'order-home') { 
     console.log('move to home'); 
     // this.nav.push(TabsPage, {"index" : 0}); 
     TabIndex = 0; 
    } 
}); 

tabs.ts

constructor(private navParams: NavParams) { 
    if (TabIndex) { 
     this.index = TabIndex; 
    } 
} 

回答

1

你可以在你的Tabs.ts(如在标签被提及和Tabs.html,将其设置使用<ion-tabs>navParams

您可以发送标签的指数navParam这个tabs.ts。然后,在此页面中使用<ion-tabs selectedIndex="2">

tabs.ts

export TabsPage{ 
    index = 1; 
    constructor(private navParams: NavParams){ 
    // This if() is for other cases where you don't want to send navParams. Like normally setting this page and selectedTab to 1. 
    if(this.navParams.data.index !== undefined){ 
     index = this.navParams.data.index; 
    } 
    } 
} 

tabs.html

<ion-tabs selectedIndex={{index}}> 
    <ion-tab>..</ion-tab> 
    ... 
</ion-tabs> 

而且app.component.ts

push.on('notification').subscribe((notification:any) => { 
    if (notification.additionalData.route == 'order-list') { 
    console.log('order-list is selected'); 
    this.nav.push(TabsPage, {"index" : 2}); 
    } else if (notification.additionalData.route == 'personal') { 
    console.log('personal is selected'); 
    this.nav.push(TabsPage, {"index" : 3}); 
    } 
}); 
+0

谢谢您的建议。有用!但是,还有一件事是,当我移动到特定页面时,标签区域被隐藏。我如何让选项卡不隐藏? 我已经试过“'tabsHideOnSubPages = “假”''上tabs.html'。但是,它适用于每个子页面,因此无法使用它。 有没有什么办法可以将'index'数据传递给tabs.ts而不用'this.nav.push'? – smchae

+0

我编辑过的问题。基本上,我想使用全局变量'TabIndex',所以我可以在'tabs.ts'中使用它,但是,当我在tabs.ts上使用TabIndex时,如何使用它? – smchae

+0

嘿,我想你错了。 TabIndex不是在两者中都可以访问的全局变量。这对两个班都是本地的。所以,你在两个引用的TabIndex是不同的。可以尝试使用'localStorage'。 2.如果你不使用'this.nav.push()'或'this.nav.setRoot()',你会如何去首页的标签页? –