For HTTP Calls, no need to unsubscribe.
subscriptions
import { Subscription } from 'rxjs';
private subscriptions: Subscription[] = [];
this.subscriptions.push(
// subscriptions
);
ngOnDestroy(): void {
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
}
takeUntil
, takeWhile
👉 takeUntil - Learn RxJS 👉 takeWhile - Learn RxJS
import { debounceTime, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
private destroy$ = new Subject();
ngOnDestroy(){
this.destroy$.next();
this.destroy$.complete();
}
// someInput: FormControl = new FormControl('');
this.someInput.valueChanges
.pipe(
debounceTime(1000),
distinctUntilChanged(),
takeUntil(this.destroy$)
).subscribe(val => {...});