I've created a http method in a service. But when i call it, it returns null and i can't figure out why. Here is the method:
objectResponse.httpCall = function ( sMethodName, postData){
var rData = null;
$http({
dataType: "json",
type: "POST",
method: 'POST',
url: sMethodName,
data: (typeof postData !== "string") ? JSON.stringify(postData) : postData,
headers: {'Content-Type': 'application/json'}
})
.success(function(data, status, headers, config) {
rData = data;
})
.error(function(data, status, headers, config) {
rData = null;
});
return rData;
}
Thank you.
$httpreturns a promise. SO you would do:-return $http(...).then(function(result) { return result.data }, function(){return null})and use it as.httpCall(..).then(function(data){//do the logic here})