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

Method open

src/material/bottom-sheet/bottom-sheet.ts:74–124  ·  view source on GitHub ↗
(
    componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
    config?: MatBottomSheetConfig<D>,
  )

Source from the content-addressed store, hash-verified

72 ): MatBottomSheetRef<T, R>;
73
74 open<T, D = any, R = any>(
75 componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
76 config?: MatBottomSheetConfig<D>,
77 ): MatBottomSheetRef<T, R> {
78 const _config = {...(this._defaultOptions || new MatBottomSheetConfig()), ...config};
79 let ref: MatBottomSheetRef<T, R>;
80
81 this._dialog.open<R, D, T>(componentOrTemplateRef, {
82 ..._config,
83 // Disable closing since we need to sync it up to the animation ourselves.
84 disableClose: true,
85 // Disable closing on detachments so that we can sync up the animation.
86 closeOnOverlayDetachments: false,
87 maxWidth: '100%',
88 container: MatBottomSheetContainer,
89 scrollStrategy: _config.scrollStrategy || createBlockScrollStrategy(this._injector),
90 positionStrategy: createGlobalPositionStrategy(this._injector)
91 .centerHorizontally()
92 .bottom('0'),
93 disableAnimations: this._animationsDisabled,
94 templateContext: () => ({bottomSheetRef: ref}),
95 providers: (cdkRef, _cdkConfig, container) => {
96 ref = new MatBottomSheetRef(cdkRef, _config, container as MatBottomSheetContainer);
97 return [
98 {provide: MatBottomSheetRef, useValue: ref},
99 {provide: MAT_BOTTOM_SHEET_DATA, useValue: _config.data},
100 ];
101 },
102 });
103
104 // When the bottom sheet is dismissed, clear the reference to it.
105 ref!.afterDismissed().subscribe(() => {
106 // Clear the bottom sheet ref if it hasn't already been replaced by a newer one.
107 if (this._openedBottomSheetRef === ref) {
108 this._openedBottomSheetRef = null;
109 }
110 });
111
112 if (this._openedBottomSheetRef) {
113 // If a bottom sheet is already in view, dismiss it and enter the
114 // new bottom sheet after exit animation is complete.
115 this._openedBottomSheetRef.afterDismissed().subscribe(() => ref.containerInstance?.enter());
116 this._openedBottomSheetRef.dismiss();
117 } else {
118 // If no bottom sheet is in view, enter the new bottom sheet.
119 ref!.containerInstance.enter();
120 }
121
122 this._openedBottomSheetRef = ref!;
123 return ref!;
124 }
125
126 /**
127 * Dismisses the currently-visible bottom sheet.

Callers

nothing calls this directly

Calls 8

bottomMethod · 0.80
centerHorizontallyMethod · 0.80
openMethod · 0.65
enterMethod · 0.65
afterDismissedMethod · 0.45
dismissMethod · 0.45

Tested by

no test coverage detected