I want return object with some data, but when I try return 'doc' variable, this variable is empty object.
here is my code:
myApp.factory('serviceDocuments', function serviceDocuments($http) {
var doc = {};
return {
getDocument: function (data) {
$http({
method: 'POST',
url: '/getDocument',
data: data
}).then(function successCallback(response) {
doc = response.data[0];
// in this place doc variable has needed data
}, function errorCallback(response) {
console.log("ups... ;(");
});
// in this place doc variable is empty object
return doc;
}
};
});