diff --git a/nativescript-angular/common/detached-loader.ts b/nativescript-angular/common/detached-loader.ts index b98fbb3b..2a433f7d 100644 --- a/nativescript-angular/common/detached-loader.ts +++ b/nativescript-angular/common/detached-loader.ts @@ -49,6 +49,13 @@ export class DetachedLoader implements OnDestroy { } public loadWithFactory(factory: ComponentFactory): ComponentRef { - return this.containerRef.createComponent(factory, this.containerRef.length, this.containerRef.injector, null); + const componentRef = factory.create(this.containerRef.injector); + this.appRef.attachView(componentRef.hostView); + + this.disposeFunctions.push(() => { + this.appRef.detachView(componentRef.hostView); + componentRef.destroy(); + }); + return componentRef; } }