I'm trying to add a boolean value to a BehaviorSubject. However, when I try to console log it says that it is undefined. What I'm doing wrong?
This is how I declare it.
isDesktopWidth: BehaviorSubject<boolean>;
And this is how I use it
changeSideBarWidth() {
if (this.innerWidth > 767) {
this.isDesktopWidth.next(true);
} else {
this.isDesktopWidth.next(false);
}
}
And then in the ngOnInit
this.changeSideBarWidth();
console.log(this.isDesktopWidth.value);
But it doesn't display anything in the console. Only an error saying that
Cannot read property 'next' of undefined