나는 체인 아래쪽으로 $http
을 호출하고 결과 핸들을 다음 처리기로 전달해야하는 약속 체인을 가지고 있습니다. 문제는 내 .then()
성공 함수가 반환 된 $http
약속을 다른 약속으로 래핑하는 것으로 나타나 내 http 약속이 페이로드로 처리되는 결과를 초래합니다. 그래서 체인의 다음 링크에서 해결할 때 http 응답보다는 약속이 생깁니다.
var statusPromise = Auth.getUserStatus();
var tokenPromise = statusPromise.then(function(status) {
if (status && status.accesstoken) {
return status.accesstoken;
} else {
return null;
}
});
var httpPromise = tokenPromise.then(function(accesstoken) {
console.log('access token', accesstoken);
var params = {
page: page,
limit: limit
};
if (accesstoken) {
params.accesstoken = accesstoken;
}
return $http.get(apiUrl + 'scenes/' + filter + '/', {
data: $.param(params),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
});
var doMoreStuffPromise = httpPromise.then(function(response) {
console.log(response); // this logs the promise as the payload, not the http response
return response.data;
});
return doMoreStuffPromise;
내 체인에 $http
약속을 체인화하려면 어떻게해야합니까?
흥미 롭습니다. 나는 야생에서이 문제를 본 적이 없으며 순수하게 이론적 인 것으로 간주했다 :-) – Bergi