I'm adding route authentication to my angular app.
For some reason when I try to navigate to the logentries
view, I cannot get the code in the resolve
function to execute.
I've added a breakpoint using Chrome developer tools, but it doesn't get hit.
The view does get loaded, however.
I thought the resolve would get hit before the controller is instantiated and the view rendered.
Why isn't it?
(function () {
'use strict';
angular.module('app')
.config(appConfig)
.run(routeAuthentication);
routeAuthentication.$inject = ['$rootScope', '$location'];
function routeAuthentication($rootScope, $location) {
$rootScope.$on('$routeChangeError', function (event, current, previous, rejection) {
if (rejection === 'Not Authenticated') {
console.log('Not Authenticated for Route');
$location.path('/');
}
});
}
appConfig.$inject = ['$routeProvider'];
function appConfig($routeProvider) {
$routeProvider
.when("/logentries", {
templateUrl: "app/views/logEntries.html",
controller: "logEntries",
resolve: function ($q, $location) {
// Code not entering here as far as I can tell.
var deferred = $q.defer();
deferred.resolve();
if (true) { // TODO - use authenticationServce
$location.path('/login');
}
return deferred.promise;
}
})
// other routes
};
})();