2017-08-02 2 views
2

タブから開いている通知ページを作成しようとしています。ページを開いた後は、新しい通知が表示されるように更新する必要があります。これらの通知は読み込み済みとしてチェックされ、タブのバッジは0になります。イオン性のタブページのコンストラクタを2回以上入力しないでください

初めて通知ページを開くときに、コンストラクタに入りますが、再度入力しません。

これまではうまくいっていましたが、動作しなくなったため、なぜか分かりません。

通知ページ;

constructor(public events: Events, public navCtrl: NavController, public 
    navParams: NavParams, private notificationservice: NotificationService, 
    private loadingCtrl: LoadingController) { 

this.notificationservice.getNotifications(AuthService.currentUser.UserId).then(
data => { 
    this.notifications = data; 

    this.notificationservice.unreadNotificationCount().then(data => { 
    if(data != 0) 
    { 
     this.notificationservice.readNotification().then(data => { 
     this.updateBadge(); 
     this.navCtrl.setRoot(this.navCtrl.getActive().component); 
     }); 
    } 
    }); 
}); 
} 

public updateBadge() 
{ 
    this.notificationservice.unreadNotificationCount().then(data => { 
    console.log(data); 
    this.events.publish('cart:updated', data); 
    }); 
} 

タブページ。

constructor(public navCtrl: NavController, public navParams: NavParams, 
private notificationservice: NotificationService, public events: Events) { 

    this.updateBadge(); 

    this.events.subscribe('cart:updated', (count) => {  
    this.badge = count; 
    }); 
} 

public updateBadge() 
{ 
    this.notificationservice.unreadNotificationCount().then(data => { 
    console.log(data); 
    this.events.publish('cart:updated', data); 
    }); 
} 

タブの表示;

Tabs with badge

+1

[。イメージとしてあなたのコードを投稿しないでください](// meta.stackoverflow.com:あなたはいくつかのコードにタブが選択されるたびに実行する必要がある場合は、ionViewDidEnterまたはionViewWillEnterライフサイクルフックを使用/ q/285551) –

+1

@suraj編集中です。 – esdoodle

答えて

1

事はページが初回のみが作成され、それがすでに存在して以来、それが再び作成されていないということです。

constructor(...) { 
    // Will be executed only once 
    // ... 
} 

ionViewWillEnter() { 
    // Will be executed every time the user selects this tab 
    // ... 
} 

// or 

ionViewDidEnter() { 
    // Will be executed every time the user selects this tab 
    // ... 
} 
1

あなたはそうのようなイオンでLifecycle Hooksを使用することができます。

ionViewWillEnter { 
    // do something when page is about to enter 
} 

ionViewDidEnter() { 
    // do something when page has entered 
} 
関連する問題