Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - ngToast clear all previous toasts and show only one

I am using Angular ngToast. I am trying to show only one toast at a time. The previously displayed toast should be hidden before displaying a new toast.There should be only one toast at a time. I tried be specifying maxNumber but doesn't work.

ngToast.create({
        className: 'info',
        content: ' New Toast',
        maxNumber: 1
        //autoDismiss: true,
        //maxOpened: 1
        //timeout: 500,
        //preventDuplicates: true,
        //preventOpenDuplicates: true
        //dismissOnClick:true
        //clickToClose: true
    });
like image 475
Divya Avatar asked Oct 31 '25 15:10

Divya


2 Answers

Here is a fiddle that might help you: https://jsfiddle.net/774a9dq4/5/

The only difference here is that before calling the new instance of toast object, just call the dismiss() which will be dismissing ALL the toast instances in DOM.

ngToast.dismiss();
ngToast.create({
       content:'I am unique <3'
 });
like image 166
Ash Avatar answered Nov 02 '25 05:11

Ash


Hope this may help:

Use the ngToast.dismiss() to clear all toasts.

Or

ngToast.dismiss(yourToastMsg) to clear a particular toast.

For more details refer to this link.

like image 37
skm Avatar answered Nov 02 '25 05:11

skm