I am new in angularjs and as starter i have a problem with accessing object outside then function. I have created a factory:
var injectParams = ['$http'];
var address = function ($http) {
var factory = {};
factory.get = function () {
return $http({
method: "POST",
url: '/address',
headers: {
'Content-Type': 'application/json'
},
data: {
service: 'address'
}
});
};
return factory;
}
And a controller method:
function getAddresses() {
address_factory.get().then(function success(response) {
$scope.billing = response.data.billing;
$scope.shipping = response.data.shipping;
console.log(response.data);
}, function error(x) {
console.log(x);
});
}
getAddresses();
The question is how can i access $scope.billing object outside getAddresses function? I have read promises in angularjs but i don't understand how to use...