Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.