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

Method attach

src/cdk/overlay/overlay-ref.ts:138–229  ·  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

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

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