Remove stack page in Ionic

Asked

Viewed 504 times

-1

I have the following structure

Home > Page 1

My Page 1 every 10 seconds performs an http request. I realized that when I move from Page 1 to Home, it continues to carry out the requisitions.

I wonder how I can remove from the stack as soon as I exit the page.

I tried to:

  ionViewWillLeave(){
    this.navController
    .push(HomePage)
    .then(() => {
      // first we find the index of the current view controller:
      const index = this.viewCtrl.index;
      // then we remove it from the navigation stack
      this.nav.remove(index - 1);
    });
  }

To change pages I use the following function:

  rotaHome() {
    this.nav.setRoot(HomePage);
  }
  • Try to make an observable unsubscribe that is making the unwanted onDestroy requests

  • I tried on onDestroy, when changing page, in several different places, but the requests continue, I got only through the way I published the answer

1 answer

0

To those who are interested, I was able to solve in the following way:

this.IntervalId = setInterval(()=> {
  this.listaPerguntas(); },12000); //A cada 5 minutos verifica se existe uma nova pergunta
}

  rotaHome() {
    clearInterval(this.IntervalId);
    this.nav.setRoot(HomePage).then(() =>
      this.navController.popToRoot()
    );
  }

I believe it is not the most recommended way, I could not understand why after pop the page continues making requests, but clearInterval worked well at the time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.