I am facing an issue where I am attempting to access the next value of a BehaviorSubject in multiple components using a service. Although I can display the value in the UI using {{ interpolation }}, I am unable to see it in the console.log. Can someone help me understand why this is happening and provide a solution?
content.component.ts:
geteventMsg;
constructor(public commonservice:CommonService) { }
ngOnInit(){
this.commonservice.currentMsg.subscribe(geteventMsg => this.geteventMsg = geteventMsg);
console.log("Current message=",this.geteventMsg); //Not coming next value
}
header.component.ts:
setMessage(){
let count=this.cnt++;
this.commonservice.changeMessage(count);
}
common.service.ts:
private messageSrc = new BehaviorSubject(0);
currentMsg = this.messageSrc.asObservable();
changeMessage(message: number) {
this.messageSrc.next(message);
}