angularjs - Angular ui-router, how do I cancel the following resolves, after one of them triggers an error - reject? -


I am using a UI router in the following code and I have two solutions.

  1. I check if there is an authentication token.
  2. I get some data from the server.

If there is no token, then I reject the resolution and redirect the user to the login page.

The problem is, the "Movie List" solution is still happening - how can I cancel the resolution?

Any thoughts? <$ ($ State provider), function ($ state provider) {$ stateProvider.state ('code', {url: '/ code', TemplateUrl: 'app / sections / code / code.tpl.html', Controller: 'CodeCtrl', solve: {/ ** * Athlete Middleware. * / UserData: ['$ q', 'session', function ($ Q, session) {var userData = session .getUserData (); if (userData. Token) {UserData back;} Return $ Q.reject ('Login')}, // If I point the trigger above, how can I fix it? Movie List: [' $ Q ',' movie service ', function ($ q, movies services) {var deferred = $ q.defer (); MoviesService. Query (). Then (function (success) {deferred.resolve (success.data);}, function (error) {$ q.reject ('home');}); refund suspended.}]}}); }];

Add UserData as a dependency for the MovieList solution function. Now the movie list will be called only when UserData is resolved.

  Movie List: ['$ q', 'moviesservices', 'user data', function ($ q, files service, user data) {var deferred = $ q.defer (); MoviesService.query () Then (function (success) {deferred.resolve (success.data);}, function (error) {$ q.reject ('home');}); Refund refund. }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -