Hows best to unsubscribe from an observable using a takeUntil.
From what I understand takeUntil automatically does the complete for you.
Below is how I normally do a unsubscribe from an observable. But not sure if done correctly. Do I really need the "this.destroyed$.complete();" if takeUntil does the complete for me?
This is my current attempt that works but unsure if best method:
private destroyed$: Subject<void> = new Subject();
ngOnIt(): void {
this.serviceA.getData
.takeUntil(this.$destroyed)
.subscribe(val => {
console.log('Current value:', val);
});
};
ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
};
I was thinking of removing the .complete in the ngOnDestory but not sure if that would cause memory leaks?