Created
July 28, 2018 09:42
-
-
Save lydemann/587eaa2bc686094226e6bd02fe53ef9a to your computer and use it in GitHub Desktop.
This file contains 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, OverlayRef } from '@angular/cdk/overlay'; | |
import { ComponentPortal } from '@angular/cdk/portal'; | |
import { Injectable } from '@angular/core'; | |
import { SpinnerOverlayComponent } from '@app/core/spinner-overlay/spinner-overlay.component'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class SpinnerOverlayService { | |
private overlayRef: OverlayRef = null; | |
constructor(private overlay: Overlay) {} | |
public show(message = '') { | |
// Returns an OverlayRef (which is a PortalHost) | |
if (!this.overlayRef) { | |
this.overlayRef = this.overlay.create(); | |
} | |
// Create ComponentPortal that can be attached to a PortalHost | |
const spinnerOverlayPortal = new ComponentPortal(SpinnerOverlayComponent); | |
const component = this.overlayRef.attach(spinnerOverlayPortal); // Attach ComponentPortal to PortalHost | |
} | |
public hide() { | |
if (!!this.overlayRef) { | |
this.overlayRef.detach(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment