ObjectUnsubscribedError: object unsubscribed error when I am using ngx-progress in angular 2

前端 未结 4 1027
自闭症患者
自闭症患者 2021-02-04 03:12

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 s

4条回答
  •  时光取名叫无心
    2021-02-04 03:32

    Updated - Angular 8

    This answer is still valid syntactically for Angular 8.


    I realize this is an old post, we're on Angular 6 now, I believe. However, I got this error and wanted to post a solution.

    I had this problem when I called .unsubscribe() directly on the object that I had called .subscribe() on. However, when you subscribe to an event, that method hands back a Subscription typed value. You need to save this (possibly on your component's class), then call unsubscribe on that Subscription object when you're done.

    Examples

    Bad Code:

    this.someEvent.subscribe(() => {
        // DO SOMETHING
    })
    ...
    this.someEvent.unsubscribe()
    

    Good Code:

    this.myEventSubscription = this.someEvent.subscribe(() => {
         // DO SOMETHING
    })
    ...
    this.myEventSubscription.unsubscribe()
    

    Again, you need to unsubscribe from the Subscription object that the .subscribe() method returns when you call it.

    Good luck!

提交回复
热议问题