Last active
January 20, 2023 06:40
-
-
Save AvocadoVenom/2ad0572f8ac4f940a00c997becb55958 to your computer and use it in GitHub Desktop.
Overlay Loading Directive > Directive
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 { Directive, ElementRef, OnInit, Input } from '@angular/core'; | |
| import { OverlayRef } from '@angular/cdk/overlay'; | |
| import { DynamicOverlay } from '@app/third-parties/angular-material/dynamic-overlay'; | |
| import { Observable } from 'rxjs'; | |
| import { ComponentPortal } from '@angular/cdk/portal'; | |
| import { LoaderComponent } from './loader/loader.component'; | |
| @Directive({ | |
| selector: '[overlayLoading]' | |
| }) | |
| export class OverlayLoadingDirective implements OnInit { | |
| @Input('overlayLoading') toggler: Observable<boolean>; | |
| private overlayRef: OverlayRef; | |
| constructor( | |
| private host: ElementRef, | |
| private dynamicOverlay: DynamicOverlay | |
| ) {} | |
| ngOnInit() { | |
| this.overlayRef = this.dynamicOverlay.createWithDefaultConfig( | |
| this.host.nativeElement | |
| ); | |
| this.toggler.subscribe(show => { | |
| if (show) { | |
| this.overlayRef.attach(new ComponentPortal(LoaderComponent)); | |
| } else { | |
| this.overlayRef.detach(); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment