So... I'm trying to learn some Angular stuff and then I reached a point where I'm stuck. In my app I'm using third party APIs so I cannot rely on $http, that's why you'll see $apply in the code.
So, basically I have this:
.when('/dashboard',{
controller : 'DashboardController',
templateUrl : 'ui/modules/dashboard/dashboard.html',
resolve : {
data : function(myService){
return myService.start();
}
}
})
So far nothing really strange. That method supposedly have a promise, right? The start function is as follows:
var start = function(){
return initializeConnection().then(function(){
return login(false);
});
};
So, basically, if everything works, all works. That's great. The thing is that, if I get promise rejection on the second function (that's login) I'm not able catch the error in this, which is my AppController which is created on top of the app (so it's always being instantiated):
$rootScope.$on("$routeChangeError", function (event, previous, current, rejection) {
console.log('Failing');
});
That's basically never called. A solution I tried that works, is to return a promise from the start function, then if any of those async functions fails, fail the returned promise. But as I see it, it should be unnecesary.
Can you point me in the right direction?