Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active January 20, 2023 06:40
Show Gist options
  • Select an option

  • Save AvocadoVenom/2ad0572f8ac4f940a00c997becb55958 to your computer and use it in GitHub Desktop.

Select an option

Save AvocadoVenom/2ad0572f8ac4f940a00c997becb55958 to your computer and use it in GitHub Desktop.
Overlay Loading Directive > Directive
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