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

Method attach

src/cdk/overlay/overlay-ref.ts:138–219  ·  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 attachedOverlays.add(this);
153
154 if (this._scrollStrategy) {
155 this._scrollStrategy.enable();
156 }
157
158 // We need to clean this up ourselves, because we're passing in an
159 // `EnvironmentInjector` below which won't ever be destroyed.
160 // Otherwise it causes some callbacks to be retained (see #29696).
161 this._afterNextRenderRef?.destroy();
162
163 // Update the position once the overlay is fully rendered before attempting to position it,
164 // as the position may depend on the size of the rendered content.
165 this._afterNextRenderRef = afterNextRender(
166 () => {
167 // The overlay could've been detached before the callback executed.
168 if (this.hasAttached()) {
169 this.updatePosition();
170 }
171 },
172 {injector: this._injector},
173 );
174
175 // Enable pointer events for the overlay pane element.
176 this._togglePointerEvents(true);
177
178 if (this._config.hasBackdrop) {
179 this._attachBackdrop();
180 }
181
182 if (this._config.panelClass) {
183 this._toggleClasses(this._pane, this._config.panelClass, true);
184 }
185
186 // Only emit the `attachments` event once all other setup is done.
187 this._attachments.next();
188 this._completeDetachContent();
189
190 // Track this overlay by the keyboard dispatcher
191 this._keyboardDispatcher.add(this);
192
193 if (this._config.disposeOnNavigation) {
194 this._locationChanges = this._location.subscribe(() => this.dispose());
195 }

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