How to hide ngx-toaster programmatically?

3.9k Views Asked by At

I use ngx-toaster with disableTimeOut true. So it won't hide automatically. But now I won't to hide it programmatically, when user leaving the page(inside the ngOnDestroy method). How can I do it?

this.toastr.error(message, status, {disableTimeOut: true});
2

There are 2 best solutions below

1
On BEST ANSWER

You just have to call the .clear() method and pass the toastId If needed

 this.toastr.clear(this.toastRef.toastId);

STACKBLITZ DEMO

0
On

Use clear()

this.toastr.clear()