From 7990167e4598667a315ffd4b7ddc8d1819806d79 Mon Sep 17 00:00:00 2001 From: Tim Sielemann Date: Mon, 15 Apr 2024 17:12:07 +0200 Subject: [PATCH] feat(angular): add openWithRef to dialog service so dialog reference can be obtained by the user (#494) Co-authored-by: Tim Sielemann --- .../catalyst/src/lib/dialog/dialog.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/angular/projects/catalyst/src/lib/dialog/dialog.service.ts b/angular/projects/catalyst/src/lib/dialog/dialog.service.ts index 405fb3bd..efdaa10a 100644 --- a/angular/projects/catalyst/src/lib/dialog/dialog.service.ts +++ b/angular/projects/catalyst/src/lib/dialog/dialog.service.ts @@ -1,4 +1,4 @@ -import { Dialog, DialogConfig } from '@angular/cdk/dialog'; +import { Dialog, DialogConfig, DialogRef } from '@angular/cdk/dialog'; import { ComponentType } from '@angular/cdk/portal'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; @@ -31,6 +31,17 @@ export class CatDialogService { component: ComponentType, config?: CatDialogConfig ): Observable { + return this.openWithRef(component, config).closed; + } + + /** + * Opens a modal dialog containing the given component and returns a reference to the dialog. + * + * @param component - The component to render as dialog content. + * @param config - The dialog configuration. + * @returns A reference to the just opened dialog. + */ + openWithRef(component: ComponentType, config?: CatDialogConfig): DialogRef { const panelClass = config?.panelClass ?? []; return this.dialog.open(component, { backdropClass: 'cat-backdrop', @@ -41,7 +52,7 @@ export class CatDialogService { maxHeight: 'calc(100vh - 64px)', maxWidth: 'calc(100vw - 64px)', ...config - }).closed; + }); } /**