how to store the $http response in a global $scope variable?
$scope.data = [];
$http({
method: 'POST',
url: '/generateId',
headers: {
'Content-Type': 'multipart/form-data'
},
data: {
name: 'userid'
},
transformRequest: function(data, headersGetter) {
var formData = new FormData();
angular.forEach(data, function(value, key) {
formData.append(key, value);
});
var headers = headersGetter();
delete headers['Content-Type'];
return formData;
}
}).
success(function(data, status, headers, config) {
$scope.data = data;
console.log('$scope.data in success-->', $scope.data);//data is coming
}).
error(function(data, status, headers, config) {
console.log('id is failed');
});
console.log('$scope.data outside-->', $scope.data);//empty array is coming
how to access the response outside the success? Is there any solution?
Thanks.