fix(dynamic_component_loader): implemented dispose for dynamically-loaded components
This commit is contained in:
@ -43,7 +43,7 @@ export class DynamicComponentLoader {
|
||||
this._viewManager.createDynamicComponentView(location, componentProtoViewRef, binding,
|
||||
injector);
|
||||
var component = this._viewManager.getComponent(location);
|
||||
var dispose = () => { throw new BaseException("Not implemented"); };
|
||||
var dispose = () => { this._viewManager.destroyDynamicComponent(location); };
|
||||
return new ComponentRef(location, component, dispose);
|
||||
});
|
||||
}
|
||||
|
@ -688,22 +688,20 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
||||
this._preBuiltObjects = null;
|
||||
this._lightDomAppInjector = null;
|
||||
this._shadowDomAppInjector = null;
|
||||
|
||||
this._strategy.callOnDestroy();
|
||||
|
||||
if (isPresent(this._dynamicallyCreatedComponentBinding) &&
|
||||
this._dynamicallyCreatedComponentBinding.callOnDestroy) {
|
||||
this._dynamicallyCreatedComponent.onDestroy();
|
||||
}
|
||||
|
||||
this.destroyDynamicComponent();
|
||||
this._strategy.clearInstances();
|
||||
|
||||
this._dynamicallyCreatedComponent = null;
|
||||
this._dynamicallyCreatedComponentBinding = null;
|
||||
|
||||
this._constructionCounter = 0;
|
||||
}
|
||||
|
||||
destroyDynamicComponent(): void {
|
||||
if (isPresent(this._dynamicallyCreatedComponentBinding) &&
|
||||
this._dynamicallyCreatedComponentBinding.callOnDestroy) {
|
||||
this._dynamicallyCreatedComponent.onDestroy();
|
||||
this._dynamicallyCreatedComponentBinding = null;
|
||||
this._dynamicallyCreatedComponent = null;
|
||||
}
|
||||
}
|
||||
|
||||
hydrate(injector: Injector, host: ElementInjector, preBuiltObjects: PreBuiltObjects): void {
|
||||
var p = this._proto;
|
||||
|
@ -133,6 +133,14 @@ export class AppViewManager {
|
||||
this._destroyFreeEmbeddedView(parentView, boundElementIndex, internalView(viewRef));
|
||||
}
|
||||
|
||||
destroyDynamicComponent(location: ElementRef) {
|
||||
var hostView = internalView(location.parentView);
|
||||
var ei = hostView.elementInjectors[location.boundElementIndex];
|
||||
var componentView = hostView.componentChildViews[location.boundElementIndex];
|
||||
ei.destroyDynamicComponent();
|
||||
this._destroyComponentView(hostView, location.boundElementIndex, componentView);
|
||||
}
|
||||
|
||||
createViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
|
||||
protoViewRef: ProtoViewRef, context: ElementRef = null,
|
||||
injector: Injector = null): ViewRef {
|
||||
|
Reference in New Issue
Block a user