Component A shows notifications count. Whereas, Component B gets live count of notificationss which I'm emitting it and subscribing the value in Component A. For some reason, the count gets updated only when I make page transition.
In a gist, here's what I'm doing.
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;
});
}
In my Count Service, I'm using EventEmitter variables like this
export class CountService {
unreadCount = new EventEmitter();
setCount(count) {
this.unreadCount.emit(count);
}
Could you please let me know how could I get the real time count updated whenever a notification is received.