import { Injectable , NgZone } from '@angular/core' ; import { MatSnackBar , MatSnackBarConfig } from '@angular/material/snack-bar' ; @ Injectable ( ) export class SnackbarService { constructor ( private readonly snackBar , private readonly zone ) { } default ( message ) { this . show ( message , { duration : 2000 , panelClass : 'default-notification-overlay' } ) ; } info ( message ) { this . show ( message , { duration : 2000 , panelClass : 'info-notification-overlay' } ) ; } success ( message ) { this . show ( message , { duration : 2000 , panelClass : 'success-notification-overlay' } ) ; } warn ( message ) { this . show ( message , { duration : 2500 , panelClass : 'warning-notification-overlay' } ) ; } error ( message ) { this . show ( message , { duration : 3000 , panelClass : [ 'error-notification-overlay' ] , } ) ; } private show ( message , configuration ) { this . zone . run ( ( ) => this . snackBar . open ( message , null , configuration ) ) ; } }