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

Method open

src/cdk/dialog/dialog.ts:116–163  ·  view source on GitHub ↗
(
    componentOrTemplateRef: ComponentType<C> | TemplateRef<C>,
    config?: DialogConfig<D, DialogRef<R, C>>,
  )

Source from the content-addressed store, hash-verified

114 ): DialogRef<R, C>;
115
116 open<R = unknown, D = unknown, C = unknown>(
117 componentOrTemplateRef: ComponentType<C> | TemplateRef<C>,
118 config?: DialogConfig<D, DialogRef<R, C>>,
119 ): DialogRef<R, C> {
120 const defaults = (this._defaultOptions || new DialogConfig()) as DialogConfig<
121 D,
122 DialogRef<R, C>
123 >;
124 config = {...defaults, ...config};
125 config.id = config.id || this._idGenerator.getId('cdk-dialog-');
126
127 if (
128 config.id &&
129 this.getDialogById(config.id) &&
130 (typeof ngDevMode === 'undefined' || ngDevMode)
131 ) {
132 throw Error(`Dialog with id "${config.id}" exists already. The dialog id must be unique.`);
133 }
134
135 const overlayConfig = this._getOverlayConfig(config);
136 const overlayRef = createOverlayRef(this._injector, overlayConfig);
137 const dialogRef = new DialogRef(overlayRef, config);
138 const dialogContainer = this._attachContainer(overlayRef, dialogRef, config);
139
140 (dialogRef as {containerInstance: DialogContainer}).containerInstance = dialogContainer;
141
142 // If this is the first dialog that we're opening, hide all the non-overlay content.
143 if (!this.openDialogs.length) {
144 // Resolve this ahead of time, because some internal apps
145 // mock it out and depend on it being synchronous.
146 const overlayContainer = this._overlayContainer.getContainerElement();
147
148 if (dialogContainer._focusTrapped) {
149 dialogContainer._focusTrapped.pipe(take(1)).subscribe(() => {
150 this._hideNonDialogContentFromAssistiveTechnology(overlayContainer);
151 });
152 } else {
153 this._hideNonDialogContentFromAssistiveTechnology(overlayContainer);
154 }
155 }
156
157 this._attachDialogContent(componentOrTemplateRef, dialogRef, dialogContainer, config);
158 (this.openDialogs as DialogRef<R, C>[]).push(dialogRef);
159 dialogRef.closed.subscribe(() => this._removeOpenDialog(dialogRef, true));
160 this.afterOpened.next(dialogRef);
161
162 return dialogRef;
163 }
164
165 /**
166 * Closes all of the currently-open dialogs.

Callers

nothing calls this directly

Calls 11

getDialogByIdMethod · 0.95
_getOverlayConfigMethod · 0.95
_attachContainerMethod · 0.95
_attachDialogContentMethod · 0.95
_removeOpenDialogMethod · 0.95
createOverlayRefFunction · 0.90
getContainerElementMethod · 0.80
pushMethod · 0.65
getIdMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected