import { Injectable } from '@angular/core'; export class ModalConfig { title: string; headerCloseButton = true; customModal: string[]; yesNoButtons = false; saveCancelButtons = false; okButtons = false; disableOverrideBodyPosition = false; disableOutsideClickDismiss = false; mode?: ModalMode; callback: (result: ModalResult) => void; } export enum ModalResult { Yes, No, Save, Cancel, Ok, Dismiss } export enum ModalMode { Default, Delete } export class ModalData { type?: string; description?: string; } @Injectable({ providedIn: 'root' }) export class ModalService { private modals: any[] = []; add(modal: any) { // add modal to array of active modals this.modals.push(modal); } remove(id: string) { // remove modal from array of active modals this.modals = this.modals.filter((x) => x.id !== id); } open(id: string, config: ModalConfig, clearAllModals: boolean = false, data: ModalData = null) { if (clearAllModals) { this.modals.forEach((m) => { m.close(); }); } // open modal specified by id const modal: any = this.modals.find((x) => x.id === id); modal.open(config, data); } close(id: string) { // close modal specified by id const modal: any = this.modals.find((x) => x.id === id); modal.close(); } }