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

Method attachOverlay

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

Attaches the overlay.

()

Source from the content-addressed store, hash-verified

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