Un de mes collègues m'a demandé s'il fallait se désinscrire de l'observable afterClosed() d'un Dialog.
Nous utilisons le modèle takeUntil pour nous désinscrire de tous les Observables sur 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();
}
Est-il donc nécessaire de se désinscrire de l'Observable afterClosed() ?
dialogRef.afterClosed().subscribe(
(data) => {
console.log(data);
}
},
);
ou ?
dialogRef.afterClosed()
.pipe(
takeUntil(this.destroy$)
)
.subscribe(
(data) => {
console.log(data);
},
);