Component A
displays the current notification count. Meanwhile, Component B
is responsible for receiving and updating the live count of notifications which are emitted and subscribed to in Component A
. Interestingly, the count only updates when a page transition occurs.
To summarize what I'm trying to achieve:
Component B
ngOnInit(){
this.handleRealTimeCount();
}
handleRealTimeCount() {
this.countSvc
.getCount()
.subscribe((res: any) => {
this.countSvc.setCount(
res.count
);
});
}
Component A
this.getUnreadCount();
}
getUnreadCount() {
this.countSvc.unreadCount.subscribe((res) => {
this.notificationsCount = res;
});
}
Within my Count Service, I utilize EventEmitter
variables like so:
export class CountService {
unreadCount = new EventEmitter();
setCount(count) {
this.unreadCount.emit(count);
}
I am seeking advice on how to ensure that the real-time count updates whenever a new notification is received.