import { Injectable, ElementRef, Injector } from '@angular/core'; import { Overlay, ComponentType } from '@angular/cdk/overlay'; import { MwOverlayComponent, MwBaseOverlayComponent, } from './overlay.component'; import { MwOverlayOptions } from './overlay.models'; @Injectable() export class MwOverlayService { private hostRef: ElementRef; private portals: MwBaseOverlayComponent[] = []; constructor(private overlay: Overlay) {} create( component: ComponentType, hostRef: ElementRef, options?: MwOverlayOptions, injector?: Injector ): MwOverlayComponent { this.hostRef = hostRef; const portal = new MwOverlayComponent(component, this.overlay, injector); this.portals.push(portal); portal.setup(this.hostRef, options); return portal; } }