From 1dca81bbc4a1a05a9eefe13988848124885f3178 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Mon, 21 Sep 2020 12:09:06 -0300 Subject: [PATCH] fix(detached-loader): detach loadWithFactory (#2260) --- nativescript-angular/common/detached-loader.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; } }