0

I'm trying to figure out how to retrieve a user, check a boolean's value on that user's record and redirect the user based on the boolean value. If the boolean's value is true, send them somewhere else, if it's not keep doing what you're doing. The following works, but prior to the redirect it briefly shows the the profile page which I don't want to have happen. I want to grab the user, check if they are provisional and if they are redirect them before they ever see the profile page. I'm guessing there needs to be another promise in here somewhere that's fulfilled after the user is checked to be provisional or not? Could use an example.

.when("/:id", {
  templateUrl: "pages/profile.html",
  controller: "UsersCtrl",
  resolve: {
    breadcrumb: function() {
      return "PROFILE";
    }, 
    user: function(User, $route) {
      User.get({id: $route.current.params.id}).$promise.then(function(data) {
        if (data.provisional) {
          window.location = "http://www.google.com";
        } else {
          // do something else
        }
      })
    }
  }
})
Alexander Elgin
  • 6,796
  • 4
  • 40
  • 50
aressidi
  • 680
  • 1
  • 10
  • 26
  • Have a look for this [answer](http://stackoverflow.com/questions/26270757/angularjs-ng-route-how-to-make-http-request-on-resolve) or a post [here](http://blog.brunoscopelliti.com/show-route-only-after-all-promises-are-resolved/) – akniazi Dec 02 '15 at 04:14
  • You should probably just return the `User.get(...` promise in the `resolve` `user` property. From my understanding, that should make it wait – Phil Dec 02 '15 at 05:02
  • you can use a combination of `$routeChangeStart` and `$routeChangeSuccess` to control what happens during routing. see [the documentation for `$route`](https://docs.angularjs.org/api/ngRoute/service/$route#!). or the corresponding `$state` methods, for ui-router. – Claies Dec 02 '15 at 05:02

0 Answers0