所以这就是我需要做的。我正在使用Angular Deferred Bootstrap库在我的代码中,因为我需要在引导并尝试加载内容之前从 RESTful 服务器接收一些基本数据。不管怎样,一旦第一个电话解决了,我必须再打第二个电话。第二个调用是登录,取决于第一个响应中包含的某个 URL。
现在,我想在收到该数据后尝试进行登录调用(我在 .success() block 中尝试),但是一旦第一个调用解析,程序就会在登录调用完成之前开始引导;事情发生了,因为我没有在服务器上“登录”。
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;
});
});
}],
}
});
有人知道我能做什么吗?
最佳答案
嗨,因为这是一个 promise ,您可以将下一个调用链接到 then 函数,例如
$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);
})
这样第二个 Promise 将被处理到最终目的地。
关于javascript - AngularJS 中的多个 $http 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24561660/