How to rectify ObjectUnsubscribedError

Viewed 75

I have two components namely ComponentA and ComponentB. In Component A, I have a "Go to" button which navigates to Component B. In Component B, I have a hyperlink which opens up a popup that subscribes from a shared component and back button which navigates to Component A and in ngOnDestroy method the subscription is unsubscribed.

The code in Component B

 if (this.pageTitleService.isViewAllLinkClicked.observers !== null && this.pageTitleService.isViewAllLinkClicked.observers !== undefined) {
  if (this.pageTitleService.isViewAllLinkClicked.observers.length === 0) {
    this.pageSubscription = this.pageTitleService.isViewAllLinkClicked.subscribe(data => {
      if (data) {
        //pop up open logic
        this.viewAllLoadSheetDetails();
      }
    });
  }
}

ngOnDestroy() {
this.pageSubscription.unsubscribe();

}

1)I am clicking "Go to" button which takes me to Component B. 2)Clicking on hyperlink which subscribes and bring data into popup and closing the popup 2)Clicking Back button which takes me to Component A 4)Now clicking "Go to" button which causes the ObjectUnSubscribedError

I need help to handle this error.

enter image description here

0 Answers
Related