ObjectUnsubscribedError:我在angular 2中使用ngx-progress时对象取消订阅错误 [英] ObjectUnsubscribedError: object unsubscribed error when I am using ngx-progress in angular 2

查看:510
本文介绍了ObjectUnsubscribedError:我在angular 2中使用ngx-progress时对象取消订阅错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Angular 2应用程序中使用 ngx-progressbar 栏.首次加载应用程序时,它工作正常.第二次显示错误.我引用了诸如 medium.com 之类的文章作为订阅对象.我不清楚. 每次单击路由器链接时,我都需要制作进度条.

I am using ngx-progressbar bar in Angular 2 application. When app loading first it is working fine. second time it is showing error. I referred few article like medium.com for subscribe object. I did't get clearly. I need to make progress bar every time when click the router links.

我附加了错误快照:

进度条形码:

import { Component, AfterContentInit} from '@angular/core';
import { NgProgress } from 'ngx-progressbar'
@Component({
  selector: 'link-outlet',
  template: '<ng-progress [showSpinner]="false"></ng-progress>'
})
export class RoutingDirectiveComponent implements AfterContentInit{
  constructor(private ngProgress: NgProgress) {

  }
  ngAfterContentInit(){

   this.ngProgress.start();
   setTimeout(()=>{
     this.ngProgress.done();
   }, 2000);
  }
 }

您的建议将不胜感激.

推荐答案

之所以会发生这种情况,是因为在运行进度条的同时破坏了保存进度条的组件,因此您应该将<ng-progress></ng-progress>放在根组件中(或将其放置在根组件中).不会被破坏的组件)

This is happening because the component that holds the progressbar is being destroyed while the progressbar is running, so you should put <ng-progress></ng-progress> in a root component (or a component that does not get destroyed)

如果您对HTTP请求使用进度,则有一个名为 automagic进度栏的新功能,您可能想尝试一下!

If you are using the progress for http requests there is a new feature called automagic progressbar, you might want to try it out!

从v2.1.1开始,您可以在任何地方使用该组件而不会出现该错误

Since v2.1.1, you can use the component anywhere without getting that error

这篇关于ObjectUnsubscribedError:我在angular 2中使用ngx-progress时对象取消订阅错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆