MCPcopy Index your code
hub / github.com/angular/components / open

Method open

src/material/dialog/dialog.ts:134–206  ·  view source on GitHub ↗
(
    componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
    config?: MatDialogConfig<D>,
  )

Source from the content-addressed store, hash-verified

132 ): MatDialogRef<T, R>;
133
134 open<T, D = any, R = any>(
135 componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
136 config?: MatDialogConfig<D>,
137 ): MatDialogRef<T, R> {
138 let dialogRef: MatDialogRef<T, R>;
139 config = {...(this._defaultOptions || new MatDialogConfig()), ...config};
140 config.id = config.id || this._idGenerator.getId('mat-mdc-dialog-');
141 config.scrollStrategy = config.scrollStrategy || this._scrollStrategy();
142
143 const cdkRef = this._dialog.open<R, D, T>(componentOrTemplateRef, {
144 ...config,
145 positionStrategy: createGlobalPositionStrategy(this._injector)
146 .centerHorizontally()
147 .centerVertically(),
148 // Disable closing since we need to sync it up to the animation ourselves.
149 disableClose: true,
150 // Closing is tied to our animation so the close predicate has to be implemented separately.
151 closePredicate: undefined,
152 // Disable closing on destroy, because this service cleans up its open dialogs as well.
153 // We want to do the cleanup here, rather than the CDK service, because the CDK destroys
154 // the dialogs immediately whereas we want it to wait for the animations to finish.
155 closeOnDestroy: false,
156 // Disable closing on detachments so that we can sync up the animation.
157 // The Material dialog ref handles this manually.
158 closeOnOverlayDetachments: false,
159 disableAnimations:
160 this._animationsDisabled ||
161 config.enterAnimationDuration?.toLocaleString() === '0' ||
162 config.exitAnimationDuration?.toString() === '0',
163 container: {
164 type: this._dialogContainerType,
165 providers: () => [
166 // Provide our config as the CDK config as well since it has the same interface as the
167 // CDK one, but it contains the actual values passed in by the user for things like
168 // `disableClose` which we disable for the CDK dialog since we handle it ourselves.
169 {provide: this.dialogConfigClass, useValue: config},
170 {provide: DialogConfig, useValue: config},
171 ],
172 },
173 templateContext: () => ({dialogRef}),
174 providers: (ref, cdkConfig, dialogContainer) => {
175 dialogRef = new this._dialogRefConstructor(ref, config, dialogContainer);
176 dialogRef.updatePosition(config?.position);
177 return [
178 {provide: this._dialogContainerType, useValue: dialogContainer},
179 {provide: this._dialogDataToken, useValue: cdkConfig.data},
180 {provide: this._dialogRefConstructor, useValue: dialogRef},
181 ];
182 },
183 });
184
185 // This can't be assigned in the `providers` callback, because
186 // the instance hasn't been assigned to the CDK ref yet.
187 (dialogRef! as {componentRef: ComponentRef<T>}).componentRef = cdkRef.componentRef!;
188 dialogRef!.componentInstance = cdkRef.componentInstance!;
189
190 this.openDialogs.push(dialogRef!);
191 this.afterOpened.next(dialogRef!);

Callers

nothing calls this directly

Calls 11

_getAfterAllClosedMethod · 0.95
centerVerticallyMethod · 0.80
centerHorizontallyMethod · 0.80
toStringMethod · 0.80
afterClosedMethod · 0.80
openMethod · 0.65
pushMethod · 0.65
getIdMethod · 0.45
updatePositionMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected