MCPcopy
hub / github.com/angular/components / attach

Method attach

src/cdk/overlay/overlay-ref.ts:131–211  ·  view source on GitHub ↗

* Attaches content, given via a Portal, to the overlay. * If the overlay is configured to have a backdrop, it will be created. * * @param portal Portal instance to which to attach the overlay. * @returns The portal attachment result.

(portal: Portal<any>)

Source from the content-addressed store, hash-verified

129 * @returns The portal attachment result.
130 */
131 attach(portal: Portal<any>): any {
132 if (this._disposed) {
133 return null;
134 }
135
136 // Insert the host into the DOM before attaching the portal, otherwise
137 // the animations module will skip animations on repeat attachments.
138 this._attachHost();
139
140 const attachResult = this._portalOutlet.attach(portal);
141 this._positionStrategy?.attach(this);
142 this._updateStackingOrder();
143 this._updateElementSize();
144 this._updateElementDirection();
145
146 if (this._scrollStrategy) {
147 this._scrollStrategy.enable();
148 }
149
150 // We need to clean this up ourselves, because we're passing in an
151 // `EnvironmentInjector` below which won't ever be destroyed.
152 // Otherwise it causes some callbacks to be retained (see #29696).
153 this._afterNextRenderRef?.destroy();
154
155 // Update the position once the overlay is fully rendered before attempting to position it,
156 // as the position may depend on the size of the rendered content.
157 this._afterNextRenderRef = afterNextRender(
158 () => {
159 // The overlay could've been detached before the callback executed.
160 if (this.hasAttached()) {
161 this.updatePosition();
162 }
163 },
164 {injector: this._injector},
165 );
166
167 // Enable pointer events for the overlay pane element.
168 this._togglePointerEvents(true);
169
170 if (this._config.hasBackdrop) {
171 this._attachBackdrop();
172 }
173
174 if (this._config.panelClass) {
175 this._toggleClasses(this._pane, this._config.panelClass, true);
176 }
177
178 // Only emit the `attachments` event once all other setup is done.
179 this._attachments.next();
180 this._completeDetachContent();
181
182 // Track this overlay by the keyboard dispatcher
183 this._keyboardDispatcher.add(this);
184
185 if (this._config.disposeOnNavigation) {
186 this._locationChanges = this._location.subscribe(() => this.dispose());
187 }
188

Callers

nothing calls this directly

Calls 15

_attachHostMethod · 0.95
_updateStackingOrderMethod · 0.95
_updateElementSizeMethod · 0.95
hasAttachedMethod · 0.95
updatePositionMethod · 0.95
_togglePointerEventsMethod · 0.95
_attachBackdropMethod · 0.95
_toggleClassesMethod · 0.95
disposeMethod · 0.95
detachMethod · 0.95

Tested by

no test coverage detected