import { Injectable } from '@angular/core' ; import { MessageBoxComponent } from './message-box.component' ; import { MatDialog } from '@angular/material/dialog' ; @ Injectable ( ) export class MessageBoxService { constructor ( public dialog ) { } async infoSync ( message , title = 'Info' , width = '300px' ) { return await this . info ( message , title , width ) ; } info ( message , title = 'Info' , width = '300px' ) { return new Promise ( ( resolve , reject ) => { const dialogRef = this . dialog . open ( MessageBoxComponent , { width : width , data : null , } ) ; dialogRef . componentInstance . title = title ; dialogRef . componentInstance . message = message ; dialogRef . componentInstance . isInfo = true ; dialogRef . componentInstance . yes . subscribe ( ( modal ) => { dialogRef . close ( ) ; resolve ( true ) ; } ) ; dialogRef . componentInstance . no . subscribe ( ( modal ) => { dialogRef . close ( ) ; reject ( ) ; } ) ; } ) ; } async errorSync ( message , title = 'Error' , width = '300px' ) { return await this . error ( message , title , width ) ; } error ( message , title = 'Error' , width = '300px' ) { return new Promise ( ( resolve , reject ) => { const dialogRef = this . dialog . open ( MessageBoxComponent , { width : width , data : null , } ) ; dialogRef . componentInstance . title = title ; dialogRef . componentInstance . message = message ; dialogRef . componentInstance . isError = true ; dialogRef . componentInstance . yes . subscribe ( ( modal ) => { dialogRef . close ( ) ; resolve ( true ) ; } ) ; dialogRef . componentInstance . no . subscribe ( ( modal ) => { dialogRef . close ( ) ; reject ( ) ; } ) ; } ) ; } }