Other

Other things you can do with Better Toast.

Programmatic dismiss

You can programmatically dismiss a toast by calling the dismiss() method on the ToasterService instance.

protected readonly toaster = inject(ToasterService);
const toastId = this.toaster.show('This is a toast');
this.toaster.dismiss(toastId);

Or clear all toasts by calling the clear() method instead.

protected readonly toaster = inject(ToasterService);
this.toaster.clear();

onAutoClose callback

You can pass a callback function to the onAutoClose option to be called when the toast disappears automatically after its timeout (controlled by the durationMs input).


                      
                    

If the user closes the toast, swipes it away, or you remove it with dismiss() or clear(), the library invokes onDismiss instead (if it is provided).

onDismiss callback

You can pass a callback function to the onDismiss option to be called when either the close button gets clicked or the toast is swiped.


                      
                    

When the toast auto-dismisses onDismiss is not called; if you passed an onAutoClose handler, the library invokes it instead.