Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Snackbar global configuration

I'm following the guide on Angular Material github to set custom global configuration to use on the snackbar module. This is the guide I'm following.

However, as sais in the docs, there is no export for MAT_SNACK_BAR_DEFAULT_OPTIONS only MAT_SNACK_BAR_DATA but it's not overriding the default configuration.

This is what I tried:

import { MatSnackBarModule, MAT_SNACK_BAR_DATA } from '@angular/material/snack-bar';

providers: [
    { provide: MAT_SNACK_BAR_DATA, useValue: { duration: 2500 } }
]

I also tried like this:

{ provide: MatSnackBarConfig, useValue: { duration: 2500 } }
{ provide: MatSnackBarConfig, useClass: SnackClass }

But none of the options is working. The snack never auto dismiss after the specified time.

like image 994
celsomtrindade Avatar asked May 03 '18 15:05

celsomtrindade


1 Answers

import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '@angular/material/snack-bar';

providers: [
  {provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: {duration: 2500}}
]
like image 143
Mangesh Daundkar Avatar answered Oct 29 '22 19:10

Mangesh Daundkar