如何以编程方式隐藏 ngx-toaster?

Sam*_*a K 2 angular ngx-toastr

我将 ngx-toaster 与disableTimeOuttrue 一起使用。所以它不会自动隐藏。但现在,当用户离开页面时(在 ngOnDestroy 方法内),我不会以编程方式隐藏它。我该怎么做?

this.toastr.error(message, status, {disableTimeOut: true});
Run Code Online (Sandbox Code Playgroud)

Saj*_*ran 6

您只需调用 .clear() 方法并传递 toastId 如果需要

 this.toastr.clear(this.toastRef.toastId);
Run Code Online (Sandbox Code Playgroud)

Stackblitz 演示