I am using Angular and Angular Material version 5.
Is there a way to keep the snackbar open?
For example, if an error happens, open a snackbar and set a duration or a timeout on that snackbar to be closed after 5 seconds. If another error happens, within those 5 seconds, how can I instead of closing this one, and opening another snackbar, to just increase duration of this one for few seconds?
Here is stackblitz url: https://stackblitz.com/edit/angular-j4ww8y
This doesn't answer the original question but, if you want a snackbar with indefinite duration: snackbar.open("Message", "Action", {duration: undefined});
You could try it the other way round:
Set a very high duration on the timeout, then, if no error occurs during the next 5 seconds, close it with the dismiss
method
https://material.angular.io/components/snack-bar/api
You can add a custom component inside the snackbar, instead of just text. That custom component can be in charge of updating the message
https://material.angular.io/components/snack-bar/examples
Btw, in your stackblitz, the snackbar never closes because you declared duration as
duration: 5000;
instead of
duration = 5000;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With