1

I see this topic but this solution not solve my problem.

Angularjs ui-router abstract state with resolve

I want to describe my problem shortly.

I have to state one of them is abstract (parent) two of them have resolve. two resolve make http but child state dont wait parent resolve result. how child resolve wait parent state resolve

Firstly go parent state it's ok , then go child state but child state dont wait parent http result

My plan something like this. In all state (for page refresh) i check user cookie if exist load user again (make http call)

All child state use this user information and get related data for user.

So i need to first of all complete abstract resolve http call.

.state('app', {
      url: '/app',
      abstract: true,
      templateUrl: Route.base('app.html'),
      resolve: {
          userExist: ['api', function (api) {

                  var currentUser = cacheService.getUser();

                      api.loginExistUser(currentUser).then(function (result) {
                          api.setUser(result.data, true);
                      });
          }]
      }
  })

 .state('app.myFriends', {
         url: '/myLingpals',
         templateUrl: "myFriends.html",
         controller: "myFriendsController",
         controllerAs: "vm",
         resolve: {
             myFriends: ['api' function (api) {
                 return api.get("myfriends");

             }]
         }
     })

2 Answers 2

2

Just add a return in your function :)

return api.loginExistUser(currentUser).then(function (result) {
                      api.setUser(result.data, true);
                  });
Sign up to request clarification or add additional context in comments.

1 Comment

ovvv is it realy (: i will try this solutions as soon as thanks for your answer
0

Thank for your answer walfrat. but your solition is not enough. i try something to solve problem and with your help i find the solition.

when i add parent resolve data to child state resolve dependency child resolve wait response. thanks again

 .state('app', {
  url: '/app',
  abstract: true,
  templateUrl: Route.base('app.html'),
  resolve: {
      **userExist**: ['api', function (api) {

              var currentUser = cacheService.getUser();

                  api.loginExistUser(currentUser).then(function (result) {
                      api.setUser(result.data, true);
                  });
      }]
  }
 }).state('app.myFriends', {
     url: '/myLingpals',
     templateUrl: "myFriends.html",
     controller: "myFriendsController",
     controllerAs: "vm",
     resolve: {
         myFriends: ['api','userExist', function (api,**userExist**) {

             return api.get("myfriends");

         }]
     }
 })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.