Service for opening dialogs programmatically
CngxDialogOpener
InjectablePrimaryv0.1.0
projects/common/dialog/dialog/dialog.service.ts
Import#
import { CngxDialogOpener } from '@cngx/common/dialog'
Description#
Service for opening dialogs programmatically.
Works like MatDialog.open() - pass a component type and config,
get back a typed CngxDialogRef<T>.
Must be provided via provideDialog().
Open a component dialog
const ref = this.dialog.open<User>(EditUserDialog, {
data: { userId: 123 },
});
ref.afterClosed().subscribe(result => {
if (result !== 'dismissed') saveUser(result);
});Inside the dialog component
class EditUserDialog {
private readonly data = inject(CNGX_DIALOG_DATA) as { userId: number };
private readonly dialogRef = inject(DIALOG_REF) as DialogRef<User>;
save(user: User) { this.dialogRef.close(user); }
}Index#
Methods#
Dismiss all programmatically opened dialogs.
Calls dismiss() on each open dialog in reverse order (most recent first).
Useful for route guards or global teardown.
open#
CngxDialogRefopen(component: Type, config?: CngxDialogConfig<D>) Open a dialog with the given component.
@paramcomponent
Type- The component type to render inside the dialog.
- Optional dialog configuration.
A typed CngxDialogRef<T> for reading the result and controlling the dialog.
open#
CngxDialogRefopen(templateRef: TemplateRef, config?: CngxDialogConfig<D>) Open a dialog with the given template.
@paramtemplateRef
TemplateRef- The template to render inside the dialog.
- Optional dialog configuration.
A typed CngxDialogRef<T>.
open#
CngxDialogRefopen(content: Type | TemplateRef, config: CngxDialogConfig<D>) @paramcontent
Type | TemplateRef