mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(core): unregister onDestroy in outputToObservable (#61882)
We should remove the `onDestroy` listener once subscription is unsubscribed because components might not be destroyed yet, but they still would capture subscribers. PR Close #61882
This commit is contained in:
parent
eb20c1f710
commit
e81ea0c3dd
1 changed files with 5 additions and 2 deletions
|
|
@ -24,9 +24,12 @@ export function outputToObservable<T>(ref: OutputRef<T>): Observable<T> {
|
|||
// Complete the observable upon directive/component destroy.
|
||||
// Note: May be `undefined` if an `EventEmitter` is declared outside
|
||||
// of an injection context.
|
||||
destroyRef?.onDestroy(() => observer.complete());
|
||||
const unregisterOnDestroy = destroyRef?.onDestroy(() => observer.complete());
|
||||
|
||||
const subscription = ref.subscribe((v) => observer.next(v));
|
||||
return () => subscription.unsubscribe();
|
||||
return () => {
|
||||
subscription.unsubscribe();
|
||||
unregisterOnDestroy?.();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue