i want to share a variable between both methods of $http.get request of angular js my code looks like this
app.run(function($rootScope,$http) {
$rootScope.checkSession = function(){
window.a = false;
$http.get('/data/url')
.success(function(response) {
window.a = true;
})
.error(function(response){
window.a = false;
});
return window.a;
};
});
and my controller code looks like this
app.controller('profileController', function($scope, $rootScope) {
alert($rootScope.checkSession());
});
it is always output false while if i alert response in both functions it works fine.