i new angularjs. how can return response of "response.data" typical function? because $http
generates promise, when function finishes doesn't return server response.
in controller have:
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; }); };
if do:
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; };
the return temp
doesn't have data because returns before data, if wait example 10 seconds before return.
how can return data in synchronous way?
thanks!!
try this.
this.getresults = function(){ return $http.get(url).then(function(res){ //resquest successs }, function(err){ //resquest fail }); }
and
myfooservice.getresults().then(...);
Comments
Post a Comment