Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put the action button when using the "snackBar.openFromComponent()" method in MatSnackBar?

I using MatSnackBar for notifications and I would like to have an action button in the snack-bar. How do I insert one when I am using "snackBar.openFromComponent()" method?

Here is my code

like image 692
YulePale Avatar asked Dec 27 '18 19:12

YulePale


People also ask

How do I use snackbar in service?

Import the snackBarService and inject it inside the constructor of the component, in which you want to use the Snackbar. This will create an instance of the service say snackBService. Now call the openSnackBar function wherever it is required, with the help of snackBService.

How do you close a snackbar mat?

A snackbar can be dismissed manually by calling the dismiss method on the MatSnackBarRef returned from the call to open . Only one snackbar can ever be opened at one time. If a new snackbar is opened while a previous message is still showing, the older message will be automatically dismissed.

What is a snack bar in angular?

The <MatSnackBar>, an Angular Directive, is used to show a notification bar to show on mobile devices as an alternative of dialogs/popups. In this chapter, we will showcase the configuration required to show a snack bar using Angular Material.


1 Answers

Thanks to this answer I was able to solve my problem.

Here is a working demo with the added action button.

like image 76
YulePale Avatar answered Sep 28 '22 05:09

YulePale