I got asked by one of my colleagues if we need to unsubscribe from the afterClosed() Observable of a Dialog.
We are using the takeUntil pattern to unsubscribe from all Observables on ngOnDestroy().
this.backEvent = fromEvent(window, 'popstate')
.pipe(
takeUntil(this.destroy$)
)
.subscribe(
() => {
this.navigationService.backClicked = true;
this.navigationService.navigateBackToDirectoryCenter();
}
);
ngOnDestroy()
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
So is it necessary to unsubscribe from afterClosed() Observable?
dialogRef.afterClosed().subscribe(
(data) => {
console.log(data);
}
},
);
or?
dialogRef.afterClosed()
.pipe(
takeUntil(this.destroy$)
)
.subscribe(
(data) => {
console.log(data);
},
);