微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Angular 中的 toastr 通知之后呈现另一个页面

如何解决在 Angular 中的 toastr 通知之后呈现另一个页面

我正在尝试在 toastr 通知消失后呈现导航另一个页面

  showToasterWarning(){
    this.notifyService.showWarning("No Data Found for this Date!","");
    
}

notifyService 是 toastr 的服务。

在我的代码中:

if(array == []){
this.showToasterWarning();
}

通知消失后意味着在 4 或 5 秒后我想使用以下方法导航另一个页面

this.router.navigate(..........);

只有在 toastr 消失后,我才想转到另一个页面

ngx-toastr 中的任何选项可以在通知消失后执行任何操作吗?

解决方法

请试试这个!

this.toastr.info('No Data Found for this Date!')
      .onHidden 
      .subscribe(() => this.router.navigateByUrl('......'));
})
,

Ngx-toast 包在 toastr 隐藏时为我们提供了一个可观察的对象。

显示toastr后,您可以获取其实例并使用“onHidden”属性。

    const toast = this.toastr.success('Hello!');
    toast.onHidden.subscribe(() => {
     console.log('Toast hidden');
     this.router.navigate(....)
    });

我在stackblitz

中做了一个例子

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。