If I were to subscribe to an Observable without an object of type "Subscription," how can I properly unsubscribe from it?
For instance, if my code looks something like this:
this.subscription = bla ...
I know I can easily unsubscribe using the following method within ngOnDestroy():
this.subscription.unsubscribe();
But what happens when my code looks more like this:
ngOnInit() {
this.isLoggedIn$ = this.authService.isLoggedIn();
this.isLoggedIn$.subscribe(res => {
if (res) {
this.isLoggedIn = true;
}
else {
this.isLoggedIn = false;
}
});
}
How do I go about unsubscribing in this scenario? Is it even necessary to unsubscribe? If not, why is that so?