fix(upgrade): leak when angular1 destroys element
Fixes #6401 Closes #7935
This commit is contained in:
parent
74e2bd7e3e
commit
9be04f8d38
|
@ -160,7 +160,7 @@ export class DowngradeNg2ComponentAdapter {
|
|||
}
|
||||
|
||||
registerCleanup() {
|
||||
this.element.bind('$remove', () => this.viewManager.destroyRootHostView(this.hostViewRef));
|
||||
this.element.bind('$destroy', () => this.viewManager.destroyRootHostView(this.hostViewRef));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -230,6 +230,35 @@ export function main() {
|
|||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should properly run cleanup when ng1 directive is destroyed',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var adapter: UpgradeAdapter = new UpgradeAdapter();
|
||||
var ng1Module = angular.module('ng1', []);
|
||||
var onDestroyed: EventEmitter<string> = new EventEmitter<string>();
|
||||
|
||||
ng1Module.directive('ng1', () => {
|
||||
return {
|
||||
template: '<div ng-if="!destroyIt"><ng2></ng2></div>',
|
||||
controller: function($rootScope, $timeout) {
|
||||
$timeout(function() { $rootScope.destroyIt = true; });
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var Ng2 = Component({selector: 'ng2', template: 'test'})
|
||||
.Class({
|
||||
constructor: function() {},
|
||||
ngOnDestroy: function() { onDestroyed.emit('destroyed'); }
|
||||
});
|
||||
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
|
||||
var element = html('<ng1></ng1>');
|
||||
adapter.bootstrap(element, ['ng1'])
|
||||
.ready((ref) => {onDestroyed.subscribe(() => {
|
||||
ref.dispose();
|
||||
async.done();
|
||||
})});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('upgrade ng1 component', () => {
|
||||
|
|
Loading…
Reference in New Issue