Skip to main content
cngx-src documentation

CngxDialogRef

Classv0.1.0

projects/common/dialog/dialog/dialog.service.ts

Import#

import { CngxDialogRef } from '@cngx/common/dialog'

Description#

Reference to a programmatically opened dialog.

Returned by CngxDialogOpener.open(). Provides both Signal-based access (state, result) and Observable convenience methods (afterClosed(), afterOpened()) for migration compatibility with MatDialogRef.

Signal-based result reading

const ref = dialog.open<boolean>(ConfirmDialog);

// In a computed or effect:
const wasCancelled = ref.result() === 'dismissed';

Observable-based result reading

ref.afterClosed().subscribe(result => {
  if (result !== 'dismissed') console.log('Confirmed:', result);
});

Index#

Methods#

afterClosed#Observable

Observable that emits the result when the dialog closes.

Emits exactly once with T | 'dismissed', then completes. Compatible with MatDialogRef.afterClosed() usage patterns.

afterOpened#Observable

Observable that emits when the dialog finishes opening.

Emits exactly once with void when the state transitions to 'open', then completes. Useful for post-open logic (e.g., focusing a specific element after animation completes).

close#void
close(value: T)

Close the dialog with a typed result value.

@paramvalueT
  • The result to deliver to consumers.
dismiss#void

Dismiss the dialog without a typed result.

Sets the result to 'dismissed'. Use for cancellation actions.

Accessors#

lifecycle#
get

Current lifecycle state of the dialog.

Possible values: 'closed', 'opening', 'open', 'closing'.

result#
get

The typed result signal.

  • undefined before the dialog closes (reset on each open cycle)
  • 'dismissed' when dismissed via Escape or backdrop click
  • T when closed with an explicit value
id#
get

Unique auto-generated ID for this dialog instance.

componentRef#ComponentRef | null
get

Reference to the content component instance.

Returns null when the dialog was opened with a TemplateRef instead of a component type.