Wrong before leave event


#1

hello. i have an weird error and i have no idea why
its a small part of a bigger app. i have two views. in the detail view there is a interval for the rest service getting data and each time it checks a specific flag for true or false. if its true the app opens the poeView. Here is an other interval for the rest service and if the specific flag of the data is false the view is changing back to the detailView.
so far so good. i started the interval in the beforeEnter event and stoped it in the beforeLeave event. i figured out that the beforeEnter event of view 2 is coming before the beforeLeave event of view 1, this is the first point that is not correct in my opinion, but not so important. i tried it also with afterEnter instead of beforeEnter. Than the order is as expected.

Now the big Problem: When the poeView is leaving first time, instead of the poe beforeLeave i get a detail beforeLeave and i have no idea why, because the detailview already was leaved before. in the second round it is working. because of this error the poeinterval is not stopping in first round and this is causing other problems in my app.

[Log] DeviceDetailCtrl: on ionicView.afterEnter (controller-detailview.js, line 73)
[Log] detailInterval start (controller-detailview.js, line 86)
[Log] DeviceDetailCtrl: on ionicView.beforeLeave (controller-detailview.js, line 100)
[Log] detailInterval stop (controller-detailview.js, line 102)

[Log] PoECtrl: on ionicView.afterEnter (controller-poe.js, line 29)
[Log] poeInterval start (controller-poe.js, line 34)
[Log] DeviceDetailCtrl: on ionicView.beforeLeave (controller-detailview.js, line 100)

[Log] DeviceDetailCtrl: on ionicView.afterEnter (controller-detailview.js, line 73)
[Log] detailInterval start (controller-detailview.js, line 86)
[Log] DeviceDetailCtrl: on ionicView.beforeLeave (controller-detailview.js, line 100)
[Log] detailInterval stop (controller-detailview.js, line 102)

[Log] PoECtrl: on ionicView.afterEnter (controller-poe.js, line 29)
[Log] poeInterval is still running (controller-poe.js, line 41)
[Log] PoECtrl: on ionicView.beforeLeave (controller-poe.js, line 17)
[Log] poeInterval stop (controller-poe.js, line 19)

[Log] DeviceDetailCtrl: on ionicView.afterEnter (controller-detailview.js, line 73)
[Log] detailInterval start (controller-detailview.js, line 86)

its a very specific case, so i dont think somebody has the same problem here, but maybe i’m lucky !? i have really no idea


#2

i found a workarround that is working for me:

var currentUrl = $state.current.url;
$scope.$on('$ionicView.enter', function(){
	var stateChangeListener = $scope.$on('$stateChangeSuccess', function(data){
		if(data.url !== currentUrl){
			console.log('leaving view');
			stateChangeListener();
		}
	});
});

i use it instead of the leave events


#3

This should be fixed in 1.0.1/nightly builds