简体   繁体   中英

how to do angularjs dynamic routing based on condtion?

i have pages like login, userdetails,store,booking .once user logged in select the store and moving to booking page without enter the userdetails.in booking page onsubmit i want to check whether userdetaills already there r not if its not there i need to redirect to my profile once user submitted details properly again need to redirect to booking page.if user logged in and submitted userdetails propery and select store that time i dont want page redirection i think here $location.path() will not work

 routes angular .module('myaccount') .config(['$stateProvider', function($stateProvider) $stateProvider .state('myaccount', { resolve:{ "check":function($location) { } }, url: '/myaccount', templateUrl: 'modules/myaccount/views/myaccount.html', controller: 'MyaccountController' }); } ]); 

I would love to know how to do this purely in the .resolve block

You could do it with a combination of resolve and controller .

resolve: {
  checkUserDetails: function (user) {
    return user.details.submitted; /** some promise **/
  }
},
controller: function (checkUserDetails, $state) {
  if (!checkUserDetails) {
    $state.go('profile');
  }
}

Ensure that you return a promise in the resolve.checkUserDetails and inject it into the controller.


Unfortunately I don't know / haven't figured out how to do something like this purely in the resolve block (which would be blimping awesome !).

So if anyone can come up with how to do that, I'd say that is your best bet.

Until then, this should do just fine .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM