refactor(upgrade): share code for destroying upgraded components between `dynamic` and `static` (#25357)
PR Close #25357
This commit is contained in:
parent
51c26b8afb
commit
71007ef9b2
|
@ -119,6 +119,13 @@ export class UpgradeHelper {
|
||||||
return this.compileHtml(template);
|
return this.compileHtml(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy($scope: angular.IScope, controllerInstance?: any) {
|
||||||
|
if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
|
||||||
|
controllerInstance.$onDestroy();
|
||||||
|
}
|
||||||
|
$scope.$destroy();
|
||||||
|
}
|
||||||
|
|
||||||
prepareTransclusion(): angular.ILinkFn|undefined {
|
prepareTransclusion(): angular.ILinkFn|undefined {
|
||||||
const transclude = this.directive.transclude;
|
const transclude = this.directive.transclude;
|
||||||
const contentChildNodes = this.extractChildNodes();
|
const contentChildNodes = this.extractChildNodes();
|
||||||
|
|
|
@ -262,13 +262,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() { this.helper.onDestroy(this.componentScope, this.controllerInstance); }
|
||||||
if (this.controllerInstance && isFunction(this.controllerInstance.$onDestroy)) {
|
|
||||||
this.controllerInstance.$onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.componentScope.$destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
setComponentProperty(name: string, value: any) {
|
setComponentProperty(name: string, value: any) {
|
||||||
this.destinationObj ![this.propertyMap[name]] = value;
|
this.destinationObj ![this.propertyMap[name]] = value;
|
||||||
|
|
|
@ -217,10 +217,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||||
if (isFunction(this.unregisterDoCheckWatcher)) {
|
if (isFunction(this.unregisterDoCheckWatcher)) {
|
||||||
this.unregisterDoCheckWatcher();
|
this.unregisterDoCheckWatcher();
|
||||||
}
|
}
|
||||||
if (this.controllerInstance && isFunction(this.controllerInstance.$onDestroy)) {
|
this.helper.onDestroy(this.$componentScope, this.controllerInstance);
|
||||||
this.controllerInstance.$onDestroy();
|
|
||||||
}
|
|
||||||
this.$componentScope.$destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private initializeBindings(directive: angular.IDirective) {
|
private initializeBindings(directive: angular.IDirective) {
|
||||||
|
|
Loading…
Reference in New Issue