Skip to content

Commit c6e655d

Browse files
JeanMecheThomas Turrell-Croft
authored and
Thomas Turrell-Croft
committed
fix(upgrade): Use takeUntil on leaky subscription. (angular#50901)
Using the life cycling hook `onDestroy` to end the subscription. fixes angular#48032 PR Close angular#50901
1 parent 654251a commit c6e655d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/upgrade/src/common/src/downgrade_component_adapter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, StaticProvider, Testability, TestabilityRegistry, Type} from '@angular/core';
9+
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, StaticProvider, Testability, TestabilityRegistry} from '@angular/core';
1010

1111
import {IAttributes, IAugmentedJQuery, ICompileService, INgModelController, IParseService, IScope} from './angular1';
1212
import {PropertyBinding} from './component_info';
@@ -211,10 +211,11 @@ export class DowngradeComponentAdapter {
211211
}
212212
const emitter = componentRef.instance[output.prop] as EventEmitter<any>;
213213
if (emitter) {
214-
emitter.subscribe({
214+
const subscription = emitter.subscribe({
215215
next: isAssignment ? (v: any) => setter!(this.scope, v) :
216216
(v: any) => getter(this.scope, {'$event': v})
217217
});
218+
componentRef.onDestroy(() => subscription.unsubscribe());
218219
} else {
219220
throw new Error(`Missing emitter '${output.prop}' on component '${
220221
getTypeName(this.componentFactory.componentType)}'!`);

0 commit comments

Comments
 (0)