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

Method attachOverlay

src/cdk/overlay/overlay-directives.ts:470–510  ·  view source on GitHub ↗

Attaches the overlay.

()

Source from the content-addressed store, hash-verified

468
469 /** Attaches the overlay. */
470 attachOverlay() {
471 if (!this._overlayRef) {
472 this._createOverlay();
473 }
474
475 const ref = this._overlayRef!;
476
477 // Update the overlay size, in case the directive's inputs have changed
478 ref.getConfig().hasBackdrop = this.hasBackdrop;
479 ref.updateSize({width: this._getWidth()});
480
481 if (!ref.hasAttached()) {
482 ref.attach(this._templatePortal);
483 }
484
485 if (this.hasBackdrop) {
486 this._backdropSubscription = ref
487 .backdropClick()
488 .subscribe(event => this.backdropClick.emit(event));
489 } else {
490 this._backdropSubscription.unsubscribe();
491 }
492
493 this._positionSubscription.unsubscribe();
494
495 // Only subscribe to `positionChanges` if requested, because putting
496 // together all the information for it can be expensive.
497 if (this.positionChange.observers.length > 0) {
498 this._positionSubscription = this._position!.positionChanges.pipe(
499 takeWhile(() => this.positionChange.observers.length > 0),
500 ).subscribe(position => {
501 this._ngZone.run(() => this.positionChange.emit(position));
502
503 if (this.positionChange.observers.length === 0) {
504 this._positionSubscription.unsubscribe();
505 }
506 });
507 }
508
509 this.open = true;
510 }
511
512 /** Detaches the overlay. */
513 detachOverlay() {

Callers 2

ngOnChangesMethod · 0.95
openMethod · 0.80

Calls 7

_createOverlayMethod · 0.95
_getWidthMethod · 0.95
getConfigMethod · 0.80
hasAttachedMethod · 0.65
attachMethod · 0.65
updateSizeMethod · 0.45
backdropClickMethod · 0.45

Tested by

no test coverage detected