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