Page Lifecycle & SetTimeOut

I have a few pages that you can navigate using Tabs.

Every page has a timer, that I start/stop when you go from one page to another.

In order to do that, I’m using the “ionViewDidEnter” to start it:

ionViewDidEnter() {
//Start periodic Refresh
this.timerId = setInterval(() => {
}, 10000);


ionViewDidLeave() {
//Stop refresh

to Stop it.

This works fine, as long as you navigate from tab to tab.

But, if you open a page from the side menu:

openEdit() {

The “ionViewDidLeave” event is not executed. I did also try using: ionViewWillLeave, ionViewWillUnload and ionViewDidUnload but none of them are executed.

Any ideas how can address that?


(I’m using RC3, but same happened in RC2)

maybe try to set the root on the main navigation?;

Thanks for the quick reply. But although it navigates fine, the event is not executed neither.

sorry to hear that. for me it worked, I learned that from the ionic github issue list. maybe you will find some ideas there

Just to double check I’m doing it right,

In my app.components.js I added:
import { App, … } from ‘ionic-angular’;

export class MyApp {
              private app: App
              ) {

Then used:;

Do I am missing something?

Thanks again!

Yes, at least it is what I had in mind unfortunately. Sorry that it didn’t worked out

No worries. Thank you very much!

Maybe you could try that:

Declare your nav like following:

 @ViewChild(Nav) nav: Nav;

and then


that’s the last idea I’ve got how to set the root from app.component

Thanks again. That is what I was originally using.

I have a similar issue to the lifecycle events not firing but not on tabs.

For me the lifcycle events (ionViewWillLeave and ionViewDidLeave) aren’t firing when I press the back icon.

damned :wink:

well then definitely don’t know, hope you will find soon

Hi leandrrr,

If you don’t mind can you please send the full code how to give timer to each page.


I’m sorry I don’t have the code handy.

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) {

//Starts a new one, and store the reference to stop it in the next enter
this.XXX.CurrentTimer = setInterval(() => {
}, ms);

Hope this helps!

Buddy, try this -

ionViewWillLeave() {

ionViewDidEnter() {
this.task = setInterval(() => {
}, 3000);

Working for me.