I am using $rootScope.$on("$stateChangeStart", …) in my run function to check for authentication. It does work within the browser but doesn’t neither in Android nor the iOS emulator.
Any ideas for this?
Or how else could I achieve an auth check before certain views without running it manually each time within the controller?
@p6n could you post your solution? I’m having a similar issue where when the app is first loaded on a real device, the $stateChangeStart event is not firing until after the first route change. However in the browser, when it first initializes, the event does fire.
I’m seeing the same issue as danicomas where the $stateChangeStart event is not firing on first load but is firing on navigation to another tab or view.
Any ideas?
EDIT:
This solved the issue for me. I added it right at the top of the .run function:
Just like @p6n, I had the $stateChangeStart inside the ionicPlatform.ready callback, which didn’t get fired on first load. When I took it out of the ionicPlatform.ready callback, and put it right in the .run function, $stateChangeStart does get fired on first load. The console.log(s) are just there to show that the event gets fired.