Remove stack page in Ionic

-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, I continue to make requests.

I would like to know how I can remove the stack as soon as I leave the page.

I've tried:

  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);
  }
    
asked by anonymous 14.08.2018 / 14:15

1 answer

0

Who cares, I managed to solve it like this:

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 think it's not the most recommended way, I could not understand why after pop the page keeps making requests, but clearInterval worked fine at the moment.

    
14.08.2018 / 15:14