我试图使通知页面从选项卡打开。打开页面后,需要自行刷新,以便新通知可以看到,并且这些通知将被检查为已读,并且标签上的徽章将为0.离子选项卡不要多次输入页面的构造函数
第一次打开通知页面时,它进入构造函数但它不会再次进入。
之前运行良好,但之后停止工作,我不知道为什么。
通知页;
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);
});
}
Tabs Page;
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 view;
[请不要发布您的代码为图像(// meta.stackoverflow.com/q/285551) –
@suraj我在编辑它。 – esdoodle