javascript - Angular resolve is rejected, but page is still loading -


this resolve function works everywhere else, , i'm stumped why profile page still executing when promise rejected. produced bug logging in, deleting token storage , trying navigate profile page. goes through authentication steps, , logs out. hits redirection line, still loads profile page, throwing errors because auth has been cleared.

any can offer great. let me know if need more info.

app.config('$routeprovider')

.when('/profile', {     templateurl: '/templates/profile.html',     controller: 'profilecontroller',     resolve: {         auth: function (sessionservice) {             sessionservice.resolve()         }     } }). otherwise({     redirectto: '/login' })  function resolve () {     if (self.isauthenticated()) {         return $q.when({auth: true})     } else {         $q.reject({auth: false})             self.logout() // first go here         }        } }  function logout () {     var auth = self.storage()     if (...) {        ...     } else {         self.clearuserauthentication() // here         $location.path('/login') // redirects here, still initializes profile controller     } } 

/profile route resolves because auth returns resolved promise (or better put it: doesn't return rejected promise , doesn't throw exception). correct code be:

.when('/profile', {     templateurl: '/templates/profile.html',     controller: 'profilecontroller',     resolve: {         auth: function (sessionservice) {             return sessionservice.resolve()         }     } }). 

note, it's important auth handler returns promise. if omit return keyword results implicit return undefined. meaningless still considered resolved promise.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -