タブから開いている通知ページを作成しようとしています。ページを開いた後は、新しい通知が表示されるように更新する必要があります。これらの通知は読み込み済みとしてチェックされ、タブのバッジは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);
});
}
タブの表示;
[。イメージとしてあなたのコードを投稿しないでください](// meta.stackoverflow.com:あなたはいくつかのコードにタブが選択されるたびに実行する必要がある場合は、
ionViewDidEnter
またはionViewWillEnter
ライフサイクルフックを使用/ q/285551) –@suraj編集中です。 – esdoodle