I've noticed recently after upgrading my rxjs version that you can't use the .next()
method this.ngUnsubscribe$.next();
as it is anymore as you would below:
export class TakeUntilComponent implements OnDestroy {
// Our magical observable that will be passed to takeUntil()
private readonly ngUnsubscribe$: Subject<void> = new Subject<void>();
// Our subject that we will subscribe to
subjectA$: Subject<number> = new Subject<number>();
constructor() {
this.subjectA$
.pipe(takeUntil(this.ngUnsubscribe$))
.subscribe(value => {
// logic goes here ...
});
}
ngOnDestroy(){
// Emit a value so that takeUntil will handle the closing of our subscriptions;
this.ngUnsubscribe$.next();
// Unsubscribe from our unsubscriber to avoid creating a memory leak
this.ngUnsubscribe$.unsubscribe();
}
}
But now you must send an argument to it like this:
this.ngUnsubscribe$.next(null);
or
this.ngUnsubscribe$.next(true);
My question is why? And what value would you know to send?