From 0fc9ec248e10fc227866e00e0bf9a3cef739ada9 Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Sat, 16 Apr 2016 13:46:53 +0300 Subject: [PATCH] fix(upgrade): clean up scope when element is destroyed Closes #8102 --- modules/angular2/src/upgrade/angular_js.ts | 1 + modules/angular2/src/upgrade/downgrade_ng2_adapter.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/upgrade/angular_js.ts b/modules/angular2/src/upgrade/angular_js.ts index 1c1fdf452f..02d6fd6d31 100644 --- a/modules/angular2/src/upgrade/angular_js.ts +++ b/modules/angular2/src/upgrade/angular_js.ts @@ -22,6 +22,7 @@ export interface IRootScopeService { $new(isolate?: boolean): IScope; $id: string; $watch(expr: any, fn?: (a1?: any, a2?: any) => void): Function; + $destroy(): any; $apply(): any; $apply(exp: string): any; $apply(exp: Function): any; diff --git a/modules/angular2/src/upgrade/downgrade_ng2_adapter.ts b/modules/angular2/src/upgrade/downgrade_ng2_adapter.ts index e0051c4ae0..6be40d39a1 100644 --- a/modules/angular2/src/upgrade/downgrade_ng2_adapter.ts +++ b/modules/angular2/src/upgrade/downgrade_ng2_adapter.ts @@ -160,7 +160,10 @@ export class DowngradeNg2ComponentAdapter { } registerCleanup() { - this.element.bind('$destroy', () => this.viewManager.destroyRootHostView(this.hostViewRef)); + this.element.bind('$destroy', () => { + this.componentScope.$destroy(); + this.viewManager.destroyRootHostView(this.hostViewRef); + }); } }