2017-04-20 18 views
0

このプラグインを使用してIonic2 Appに通知しますhttps://github.com/phonegap/phonegap-plugin-push。ユーザーが通知を受け取ると、そのデータに応じて、ページを適切に移動したいと考えています。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.htmlのように、あなたが<ion-tabs>を使用して設定)あなたのTabs.tsnavParamsを持つことができます。

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

がご提案いただきありがとうございます。できます!しかし、もう1つは、その特定のページに移動すると、タブ領域が非表示になります。タブを非表示にする方法を教えてください。 私は 'tabs.html'で' 'tabsHideOnSubPages =" false "'を試しました。ただし、すべてのサブページに適用されているため、使用できませんでした。 'this.nav.push'なしで' index'データをtabs.tsに渡す方法はありますか? – smchae

+0

私は編集した質問をしました。基本的には、グローバル変数 'TabIndex'を使いたいので、' tabs.ts'で使うことができますが、 'tabs.ts'でTabIndexを使うとどうすればいいですか? – smchae

+0

ねえ、あなたはこれが間違っていると思います。 TabIndexは、両方でアクセスするグローバル変数ではありません。両方のクラスにローカルです。したがって、両方で参照するTabIndexは異なります。 'localStorage'を試してみてください。 2. 'this.nav.push()'や 'this.nav.setRoot()'を使用しない場合は、どのようにTabsページに移動しますか? –