I am using subject which is emitting a value from one component. Then I subscribed it in another component and assigned it to a variable. The problem that I am facing is when I am printing the variable inside the subscribe function I'm able to see the value whereas It's showing default value when I am trying to print outside the subscribe function.
Can somebody explain the reason for this issue
Code
firstComponent
this.dataService.activateMenusTab.next(false);
secondComponent
this.isMediaTabActive = true;
this.dataService.activateMenusTab.subscribe((res) => {
this.isMediaTabActive = res;
console.log(this.isMediaTabActive);//printing false
});
console.log(this.isMediaTabActive);//printing true