I am trying to ensure that an asynchronous call completes before any of my routes are resolved by modifying route.resolve
as follows:
var originalWhen = $routeProvider.when;
$routeProvider.when = function(path, route) {
route.resolve || (route.resolve = {});
angular.extend(route.resolve, {
availableCodes: function($rootScope, numbersService) {
if ($rootScope.isAuthenticated) {
numbersService.getAvailableCodes().$promise.then(function(data) {
$rootScope.availableCodes = data.codes;
console.log('resolve: ' + Date.now());
});
}
}
});
return originalWhen.call($routeProvider, path, route);
};
I am puzzled by the fact that when I include a
console.log('controller: ' + Date.now())
in my controller, the logged time indicates that the controller loaded BEFORE my asynchronous call in the resolve function completed. I had assumed that the controller would not execute until after the async call in resolve was finished. What am I overlooking here?