Pages aren’t destroyed when
setRoot() is called. This messes with events.subscribe() on these pages as the handler functions are called as many times as there are supposedly destroyed pages.
in more detail:
My app is very simple. There is a
HomePage. From there you can go into two other pages (both with
this.nav.push();), on one there is a simple gallery where you can look at pictures, on the other page you take a picture and then pick a category for the thing on the picture. Once that is done, I do a
this.nav.setroot(HomePage). In the
HomePage I have a button that causes the app to upload all the pictures that haven’t been uploaded yet. Once uploadig is finished, the uploader service firesan
HomePage subscribes to that event (in the constructor).
The problem is: Once I’ve taken a couple of pictures and navigated back to the
HomePage, the action defined in subscribe of the Homepage is fired multiple times.
To check if this comes from there simply being multiple instances of
HomePage, I’ve added a random number to
HomePage in the constructor that is logged to the console whenever there is any action going on the
HomePage. So I tested it and, lo and behold, there are multiple instances of
HomePage. That’s why my app has been acting weird (to be precise: in the subsciption I’ve presented a Toast, and that toast was shown a couple of times, depending on how many
HomePages there were, this even prevented me from going to another Page until I’ve checked every single of the
So … I was really wondering what I can do here. I was trying out the whole Ionic events and was pleasantly suprised about how well it worked, but apparently I was endeared too early.
The weird thing is DOC says “They [pages] are destroyed when removed from the navigation stack (on
But apparently that is not correct as I am doing the
setRoot() back to
HomePage, and all the older
HomePage pages are still alive and triggered by my custom events.
How come my pages aren’t destroyed when I call