import { Injectable } from '@angular/core'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; @Injectable({ providedIn: 'root' }) export class MessageService { constructor( private snackbar: MatSnackBar, ) { } showMessage(message: string, action?: string, config?: MatSnackBarConfig) { let cfg = config if (!cfg) { cfg = { duration: 2000 } } this.snackbar.open(message, action, cfg); } }