【问题标题】:Toastr Not working when Routing to different page路由到不同页面时Toastr不工作
【发布时间】:2017-06-09 07:06:10
【问题描述】:

这是我的删除函数中调用该服务的代码。订阅中的成功部分无法正常工作,因为 toastr 没有出现在新页面上。但它会出现在之前的页面上(导航到另一个页面会使其消失)。

this._meetupService.deleteMeetup(id).subscribe(
                       () => {this._router.navigate(['/meetups']),
                        this.toastr.success('Successfully Deleted!');},
                        error => this.errorMessage = <any>error);

【问题讨论】:

    标签: angular navigation router toastr


    【解决方案1】:

    这是因为您需要在应用的主要组件中为 ViewContainerRef 设置路由。

    您可以通过在构造函数中设置它来做到这一点。

          constructor( public toastr: ToastsManager, vcr: ViewContainerRef) {
        this.toastr.setRootViewContainerRef(vcr);
      }
    

    P.S - 不要忘记从 '@angular/core' 导入 ViewContainerRef

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2021-01-06
      相关资源
      最近更新 更多