This works fine, as long as you navigate from tab to tab.
But, if you open a page from the side menu:
openEdit() {
this.nav.setRoot(MyNoTabPage);
}
The “ionViewDidLeave” event is not executed. I did also try using: ionViewWillLeave, ionViewWillUnload and ionViewDidUnload but none of them are executed.
This is what I remember I did, definitely not the an ideal solution, but it worked.
When executing the “setInterval”, I did store the value returned in a “global” place, in my case a singleton object that I use to keep the application status.
Then, on every “ionViewDidEnter”, I check for that id, stop the previous timer and start a new one.
In summary, since I can’t stop it on every “ionViewDidLeave”, I keep a reference and stop it in the “ionViewDidEnter”.
//Stops previous timer
if (this.XXX.CurrentTimer != null) {
clearTimeout(this.XXX.CurrentTimer);
}
//Starts a new one, and store the reference to stop it in the next enter
this.XXX.CurrentTimer = setInterval(() => {
this.refreshValues()
}, ms);