Created
October 3, 2019 22:16
-
-
Save AvocadoVenom/99bc6ee561d169c56b2db2015c27a7dc to your computer and use it in GitHub Desktop.
Overlay Loading Directive > Dynamic Overlay Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| Overlay, | |
| OverlayKeyboardDispatcher, | |
| OverlayPositionBuilder, | |
| ScrollStrategyOptions, | |
| OverlayRef | |
| } from '@angular/cdk/overlay'; | |
| import { | |
| ComponentFactoryResolver, | |
| Inject, | |
| Injector, | |
| NgZone, | |
| Renderer2, | |
| RendererFactory2, | |
| Injectable | |
| } from '@angular/core'; | |
| import { DynamicOverlayContainer } from './dynamic-overlay-container.service'; | |
| import { Directionality } from '@angular/cdk/bidi'; | |
| import { DOCUMENT } from '@angular/common'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class DynamicOverlay extends Overlay { | |
| private readonly _dynamicOverlayContainer: DynamicOverlayContainer; | |
| private renderer: Renderer2; | |
| constructor( | |
| scrollStrategies: ScrollStrategyOptions, | |
| _overlayContainer: DynamicOverlayContainer, | |
| _componentFactoryResolver: ComponentFactoryResolver, | |
| _positionBuilder: OverlayPositionBuilder, | |
| _keyboardDispatcher: OverlayKeyboardDispatcher, | |
| _injector: Injector, | |
| _ngZone: NgZone, | |
| @Inject(DOCUMENT) _document: any, | |
| _directionality: Directionality, | |
| rendererFactory: RendererFactory2 | |
| ) { | |
| super( | |
| scrollStrategies, | |
| _overlayContainer, | |
| _componentFactoryResolver, | |
| _positionBuilder, | |
| _keyboardDispatcher, | |
| _injector, | |
| _ngZone, | |
| _document, | |
| _directionality | |
| ); | |
| this.renderer = rendererFactory.createRenderer(null, null); | |
| this._dynamicOverlayContainer = _overlayContainer; | |
| } | |
| private setContainerElement(containerElement: HTMLElement): void { | |
| this.renderer.setStyle(containerElement, 'transform', 'translateZ(0)'); | |
| this._dynamicOverlayContainer.setContainerElement(containerElement); | |
| } | |
| public createWithDefaultConfig(containerElement: HTMLElement): OverlayRef { | |
| this.setContainerElement(containerElement); | |
| return super.create({ | |
| positionStrategy: this.position() | |
| .global() | |
| .centerHorizontally() | |
| .centerVertically(), | |
| hasBackdrop: true | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment