Wrong order for ionic view event


I have made 2 pages, and in each page, I make some modifications before enter and before leaving with :

$scope.$on(’$ionicView.beforeEnter’, function (e, data) {
$scope.$on(’$ionicView.beforeLeave’, function (e, data) {

I have found that when I move from page 1 to page 2, the ‘before enter’ event from page 2 is catch before the ‘before leave’ event from page 1.
It’s not the good order, you need to leave page 1 before enter page 2, the right order must be :

-> before leave page 1
-> leave page 1
-> before enter page 2
-> enter page 2


Is anyone reading this ? Some one will fix it ?


@ArnaudDev there are other events in the navigation workflow, and the “magic” happens at the delicate interface between two different projects: Ionic and angular-ui-router. It’s not realistic to hope it’ll be refactored unless there’s a really strong and compelling reason, not to mention all the apps that use it and expect it to continue working the way it works now.

I think your best strategy would be to learn how they work (even if you don’t agree with it) and then relocate your code to another stage, one better fit for what you have in mind, within that workflow that’s already there.

Check this, maybe it helps Codepen to help you understand Ionic Views, UI-Router, Cache


Hi, I’m sorry but in my world, you must leave a page before enter a new one.
Unless you find me a good reason to leave it that way I will keep my position.


Hey there. Could you test out the nightly builds? This was an issue with our view events and I believe that it has been fixed :smile:


I update the ionic lib but the issue is still here, the before enter event from the second page is fire before the before leave event from the first page.


One more thing, when you add this in main controller and in sub controller :

$scope.$on(’$ionicView.beforeEnter’, function (e, data) {
$scope.$on(’$ionicView.beforeLeave’, function (e, data) {

It is launch 2 times, by the controller and the sub controller. But the first is the sub controller and not the main one ?
Why ? I think its a problem here too.


@ArnaudDev see also https://github.com/driftyco/ionic/blob/master/test/unit/angular/directive/navView.unit.js#L1013-L1064

specially this snippet, lines 1052-1063