나는, 다음과 같은 API의 호출에
getValue: function(input) {
var deferred, url;
deferred = $q.defer();
url = "url";
$http.post(url, input).success(function(data, status, headers, config) {
return deferred.resolve({
success: true,
data: data,
status: status,
headers: headers,
config: config
});
}).error(function(data, status, headers, config) {
return deferred.resolve({
success: false,
data: data,
status: status,
headers: headers,
config: config
});
});
return deferred.promise;
}
을하는 서비스를하지만이 비동기입니다. 동기화로 변환하려면 어떻게해야합니까? (결과를 얻을 때까지 기다리게하고 싶습니다)?
약속의 내용입니다. 함수에서 반환하는 약속을 사용하여 액션을 수행하십시오. 예를 들어'deffered.promise'가'.then (function() {/ * your action * /})'을 리턴합니다. 또는 귀하의 경우 (기본적으로 HTTP 응답으로 해결되므로 게시 fn에서 귀하의 조치를 수행하십시오). – haki
나는 동기화를 할 수 없다고 생각하지만, 당신이 그것을 제어 할 수있는 약속을 사용하고, 앱이 해결/거부 될 때까지 기다릴 수 있다고 말할 수있다. –
[How to $ http AngularJS ] (http://stackoverflow.com/questions/13088153/how-to-http-synchronous-call-with-angularjs) –