Problem Statement
Show a standard takeUntil pattern to cancel streams on component destroy.
Explanation
Create a private destroy$ subject, pipe takeUntil(this.destroy$) on long-lived streams, and next/complete it in ngOnDestroy. This prevents memory leaks and cancels active HTTP or interval streams.
Code Solution
SolutionRead Only
private destroy$ = new Subject<void>();
ngOnInit(){
this.api.poll().pipe(takeUntil(this.destroy$)).subscribe();
}
ngOnDestroy(){
this.destroy$.next();
this.destroy$.complete();
}