Ionic 4 - Observable Subscribe/Unsubscribe Problem Between Some Pages


#1

I have a service that get data from Firebase and show it in Home page. I have tabs and side menu together. When i click a page in tabs and go back to home there is no problem but when i click a non-tab page and go back to home, data is disappeared. I call service at home like that:

  ngOnInit() {
    this.subscription = this.calendarService.getCalendar().subscribe(res => {
      this.events = res;
    });
  }

This is problematic itself. So i used ngOnDestroy at home page to unsubscribe like that and everything is ok:

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

I wonder about why i have to unsubscribe because of non-tab pages?

Btw i get classical v4 error at non-tabs pages: router-outlet destroyed

Can Router Outlet problem cause that subscription problem?

Thanks in advance.


#2

Hi,

if u navigate between child pages, we have a simluare error:
https://forum.ionicframework.com/t/ionic-4-navigate-between-child-routes-router-outlet-destroyed/149902/2

Do u have any solutions?

best


#3

Unfortunately no. There are lots of discussion on Google but i didn’t see a solution.

Btw i get that error when i go to a child from a tab page. Because tabs use same outlet. Problem is between outlets.


#4

FWIW, framework #15216 looks relevant.