Skip to content

Commit

Permalink
refactor: reuse method to destroy view (#9949)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Dec 12, 2024
1 parent 1144fae commit 16c4f3a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions projects/cdk/classes/portals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/// <reference types="@taiga-ui/tsconfig/ng-dev-mode" />
import type {ComponentRef, EmbeddedViewRef, Provider, TemplateRef} from '@angular/core';
import type {
ComponentRef,
EmbeddedViewRef,
Provider,
TemplateRef,
ViewRef,
} from '@angular/core';
import {
Directive,
inject,
Expand Down Expand Up @@ -56,16 +62,14 @@ export abstract class TuiPortalService {
}

public remove<C>({hostView}: ComponentRef<C>): void {
if (!hostView.destroyed) {
hostView.destroy();
}
this.removeTemplate(hostView);
}

public addTemplate<C>(templateRef: TemplateRef<C>, context?: C): EmbeddedViewRef<C> {
return this.safeHost.addTemplateChild(templateRef, context);
}

public removeTemplate<C>(viewRef: EmbeddedViewRef<C>): void {
public removeTemplate<C>(viewRef: EmbeddedViewRef<C> | ViewRef): void {
if (!viewRef.destroyed) {
viewRef.destroy();
}
Expand Down

0 comments on commit 16c4f3a

Please sign in to comment.