AngularJS를 처음 사용합니다. "response.data"응답을 일반적인 함수로 반환하려면 어떻게해야합니까? $http
이 약속을 생성하기 때문에 함수가 끝나면 서버 응답을 반환하지 않습니다. 내 컨트롤러에서
내가 가진 :
this.message2 = function() {
$http({
url : 'dataset_of_model',
method : "POST",
data : {
'experiment' : 'rcp85',
'model' : 'HadGEM2-ES',
'frequency' : 'day'
}
}).then(function(response) {
console.log('qui');
console.log(response.data);
return response.data;
}, function(response) {
//fail case
console.log(response);
console.log(fallito);
return response;
});
};
내가 할 경우이 데이터 전에 반환하기 때문에
가this.message2 = function() {
var = temp;
$http({
url : 'dataset_of_model',
method : 'POST',
data : {
'experiment' : 'rcp85',
'model' : 'HadGEM2-ES',
'frequency' : 'day'
}
}).then(function(response) {
console.log('qui');
console.log(response.data);
temp = response.data;
}, function(response) {
//fail case
console.log(response);
console.log(fallito);
return response;
});
return temp;
};
반환 temp
데이터가없는, 내가 예를 들어 10 기다릴 경우에도 돌아 오기 전 몇 초.
어떻게 동기식으로 데이터를 반환 할 수 있습니까?
감사합니다.
나는 방법이 없다 생각합니다. Javascript는 단일 스레드이며 특정 기능을 완료 할 때까지 기다리지 않아도됩니다. –
[비동기 호출의 응답을 어떻게 반환합니까?] (http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call)의 가능한 복제본 –