Attaches the overlay.
()
| 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() { |
no test coverage detected