I have a simple scenario:
service.ts:
private showComposeBoxAction = new BehaviorSubject<boolean>(null);
showComposeBox = this.showComposeBoxAction.asObservable();
openComposeBox(event:boolean) {
console.log("in openComposeBox");
this.showComposeBoxAction.next(event);
}
Component.ts:
constructor(
private _service: Service,
) {
this.subscriptions.add(
this._mailingService.showComposeBox.subscribe(event => {
if (event) {
this.displayCompose = true;
console.log("showComposeBox displayCompose", this.displayCompose);
}
})
);
}
component2.ts:
showComposeBox() {
if (this.count === 0) {
this._service.openComposeBox(true);
}
}
I have logged a msg within openComposeMsg(). Problem I am facing is that first time I am correctly subscribing to showComposeBox observable but 2nd time when subscribing even when next is not called because msg "in openComposeBox" does not log into console.
Unable to understand behavior of BehaviorSubject. What am I doing wrong?