import { Injectable } from '@angular/core' ; import { MatSnackBar } from '@angular/material' ; import { MatSnackBarRef } from '@angular/material/snack-bar/typings/snack-bar-ref' ; import { SimpleSnackBar } from '@angular/material/snack-bar/typings/simple-snack-bar' ; @ Injectable ( ) export class SnackBarService { public static readonly durationShort = 3000 ; public static readonly durationLong = 9000 ; public static readonly defaultDuration = 6000 ; private defaultAction = 'Dismiss' ; param { MatSnackBar } matSnackBar constructor ( private matSnackBar ) { } param defaultAction setDefaultAction ( defaultAction ) { this . defaultAction = defaultAction ; } param { string } message param { number } duration returns { MatSnackBarRef < SimpleSnackBar > } open ( message , duration = SnackBarService . defaultDuration ) { return this . matSnackBar . open ( message , this . defaultAction , { duration : duration } ) ; } param { string } message returns { MatSnackBarRef < SimpleSnackBar > } openShort ( message ) { return this . open ( message , SnackBarService . durationShort ) ; } param { string } message returns { MatSnackBarRef < SimpleSnackBar > } openLong ( message ) { return this . open ( message , SnackBarService . durationLong ) ; } }