I'm creating a service for an AngularJS application where I should query a ws and return a value for a variable. My problem is that when I use $http
I can not get this value to return, if I use a console.log()
... I do this:
app.service('wsService', function($http){
var callback;
$http.get('http://www.meudominio.com/ws')
.success(function (data) {
callback = data;
})
.error(function (d, s) {
callback = 'error';
})
;
//retorne o callback
return callback;
});
My problem is that if I do this my callback function does not return the date or error now if I give a console.log(data)
within .success
or .error
it returns ...
How can I send the return of this request to the external variable?