From 16c4f3a1780d0705ac7d72c7221274c4bdb137cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Thu, 12 Dec 2024 10:05:56 +0300 Subject: [PATCH] refactor: reuse method to destroy view (#9949) --- 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(); }