MCPcopy Create free account
hub / github.com/angular/components / MatDialog

Class MatDialog

src/material/dialog/dialog.ts:58–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 */
57@Service()
58export class MatDialog implements OnDestroy {
59 private _defaultOptions = inject<MatDialogConfig>(MAT_DIALOG_DEFAULT_OPTIONS, {optional: true});
60 private _scrollStrategy = inject(MAT_DIALOG_SCROLL_STRATEGY);
61 private _parentDialog = inject(MatDialog, {optional: true, skipSelf: true});
62 private _idGenerator = inject(_IdGenerator);
63 private _injector = inject(Injector);
64 protected _dialog = inject(Dialog);
65 private _animationsDisabled = _animationsDisabled();
66
67 private readonly _openDialogsAtThisLevel: MatDialogRef<any>[] = [];
68 private readonly _afterAllClosedAtThisLevel = new Subject<void>();
69 private readonly _afterOpenedAtThisLevel = new Subject<MatDialogRef<any>>();
70 protected dialogConfigClass = MatDialogConfig;
71
72 private readonly _dialogRefConstructor: Type<MatDialogRef<any>>;
73 private readonly _dialogContainerType: Type<MatDialogContainer>;
74 private readonly _dialogDataToken: InjectionToken<any>;
75
76 /** Keeps track of the currently-open dialogs. */
77 get openDialogs(): MatDialogRef<any>[] {
78 return this._parentDialog ? this._parentDialog.openDialogs : this._openDialogsAtThisLevel;
79 }
80
81 /** Stream that emits when a dialog has been opened. */
82 get afterOpened(): Subject<MatDialogRef<any>> {
83 return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpenedAtThisLevel;
84 }
85
86 private _getAfterAllClosed(): Subject<void> {
87 const parent = this._parentDialog;
88 return parent ? parent._getAfterAllClosed() : this._afterAllClosedAtThisLevel;
89 }
90
91 /**
92 * Stream that emits when all open dialog have finished closing.
93 * Will emit on subscribe if there are no open dialogs to begin with.
94 */
95 readonly afterAllClosed: Observable<void> = defer(() =>
96 this.openDialogs.length
97 ? this._getAfterAllClosed()
98 : this._getAfterAllClosed().pipe(startWith(undefined)),
99 ) as Observable<any>;
100
101 constructor() {
102 this._dialogRefConstructor = MatDialogRef;
103 this._dialogContainerType = MatDialogContainer;
104 this._dialogDataToken = MAT_DIALOG_DATA;
105 }
106
107 /**
108 * Opens a modal dialog containing the given component.
109 * @param component Type of the component to load into the dialog.
110 * @param config Extra configuration options.
111 * @returns Reference to the newly-opened dialog.
112 */
113 open<T, D = any, R = any>(
114 component: ComponentType<T>,
115 config?: MatDialogConfig<D>,

Callers

nothing calls this directly

Calls 2

_getAfterAllClosedMethod · 0.95
_animationsDisabledFunction · 0.90

Tested by

no test coverage detected