From a7ddbf208bfe9eca23a24f0836be8e5a5c9330ad Mon Sep 17 00:00:00 2001 From: splincode Date: Mon, 9 Dec 2024 19:03:59 +0300 Subject: [PATCH] refactor: reuse method to destroy view --- projects/cdk/classes/portals.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/cdk/classes/portals.ts b/projects/cdk/classes/portals.ts index 5afbf34f18e1..feea03646a6c 100644 --- a/projects/cdk/classes/portals.ts +++ b/projects/cdk/classes/portals.ts @@ -1,5 +1,11 @@ /// -import type {ComponentRef, EmbeddedViewRef, Provider, TemplateRef} from '@angular/core'; +import type { + ComponentRef, + EmbeddedViewRef, + Provider, + TemplateRef, + ViewRef, +} from '@angular/core'; import { Directive, inject, @@ -56,16 +62,14 @@ export abstract class TuiPortalService { } public remove({hostView}: ComponentRef): void { - if (!hostView.destroyed) { - hostView.destroy(); - } + this.removeTemplate(hostView); } public addTemplate(templateRef: TemplateRef, context?: C): EmbeddedViewRef { return this.safeHost.addTemplateChild(templateRef, context); } - public removeTemplate(viewRef: EmbeddedViewRef): void { + public removeTemplate(viewRef: EmbeddedViewRef | ViewRef): void { if (!viewRef.destroyed) { viewRef.destroy(); }