I'm having trouble understanding why the addition of Angular UI Router Extras causes the $stateChangeStart
event to trigger twice (on init!) in a situation where I have some asynchronous ajax check and call e.preventDefault()
.
Here is a short example of the event code:
$rootScope.$on("$stateChangeStart", function (e, toState, toParams, fromState, fromParams, error) {
console.log("$stateChangeStart");//fired twice
if(!User.data) {
e.preventDefault();
$http.get("https://randomuser.me/api/")
.success(function(data, status, headers, config) {
console.log(data);
User.data = data;
$state.go(toState, toParams);
});
}
});
Here's the full FIDDLE Example
Everything works as expected without using the extras addition.
Thank you!