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");

             }]
         }
     })
Community
  • 1
  • 1
phclummia
  • 63
  • 8

2 Answers2

2

Just add a return in your function :)

return api.loginExistUser(currentUser).then(function (result) {
                      api.setUser(result.data, true);
                  });
Walfrat
  • 5,363
  • 1
  • 16
  • 35
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");

         }]
     }
 })
phclummia
  • 63
  • 8