0

So here is what I need to do. I'm using the Angular Deferred Bootstrap library in my code because I need to receive some essential data from a RESTful server before bootstrapping and trying to load the content. Anyway, I must make a second call once the first call resolves. The second call is a login that depends on some URL that is contained in the first response.

Right now, I want to try to make the login call once I receive that data (I was trying in the .success() block) but once the first call resolves, the program begins bootstrapping before the login call is finished; things break because I'm not "logged in" on the server.

window.deferredBootstrapper.bootstrap({
                element: window.document.body,
                module: 'app',
                resolve: {
                    STARTUP_CONFIG: ['$http', function($http) {
                        return $http.get(url1 + 'blah/blah/blah/' + layout);
                    }],

                    CONTEXT_CONFIG: ['$http', function($http) {
                        return $http.get(url1 + 'blah/blah/blah/blah').
                        success(function(data) {
                            $http.post('https://' + data.url2 + '/10001/guestidentity?client_id=' + data.id).
                            success(function(result){
                                token = result.token;
                            });
                        });
                    }],
                }
            });

Anyone have any idea what I can do?

19
  • but once the first call resolves, it returns the resolved promise before the login call is finished uh.... no... it returns the unresolved promise immediately, then when it becomes resolved, the second one starts. Commented Jul 3, 2014 at 19:23
  • What I meant was that the Deferred Bootstrap library prevents my app from bootstrapping until the promise resolves. Commented Jul 3, 2014 at 19:27
  • The issue is you're returning a promise that represents the first $http rather than the second. You don't really care when the first resolves because you want it to continue after the second resolves, not the first. Dayan's answer handles that. Commented Jul 3, 2014 at 19:28
  • But I do care when the first resolves because I cannot make the second call without the data I receive from the first. Commented Jul 3, 2014 at 19:34
  • well, of course, but you don't need the bootstrap to know that. Commented Jul 3, 2014 at 19:34

1 Answer 1

1

hi since this is a promise you can chain the next call to the then function something like

  $http(url).
  then(function(response){
           //note that this shouldn't be the body of the response
           // but the entire response stream so you need to check for the status code and the body and apply and possibly apply any transformation that is needed as it will probably be just text
             // then we can start the other call
             return $http(url); 
   })

this way the second promise will be handled to the final destination.

Sign up to request clarification or add additional context in comments.

1 Comment

he shouldn't have to do any transformations other than using response.data.token rather than response.token

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.