I am making an http call to my controller through angular.js and trying to store the response in one global variable like below.
app.controller('dashBoardController', ['$scope', '$http', '$location',
function ($scope, $http, $location) {
$scope.details = [];
var init = function () {
$http({
method: 'GET',
url: urlpath + '/values'
}).success(function (response) {
$scope.workouthistory = JSON.stringify(response);
$scope.details = response;
console.log($scope.details)
});
}
init();
alert($scope.details)
]);
But when I try to print the response that I stored globally in an array I am getting an blank response. But, the console inside the method prints the response correctly. Kindly, help me figure out how to store this response globally.