Angular - RxJS and Observables Fundamentals
Given this Angular component code:
What happens if
export class SampleComponent implements OnInit, OnDestroy {
data$ = this.service.getData();
subscription: Subscription | undefined;
ngOnInit() {
this.subscription = this.data$.subscribe(value => console.log(value));
}
ngOnDestroy() {
this.subscription?.unsubscribe();
}
}What happens if
ngOnDestroy does not unsubscribe?