Can anyone please let me know how to store logged in user data into global scope of AngularJS,
My Login services is looked like this
App.service('Auth', function($http){
return {
isLogin:function(callback){
$http.get('api/auth/checkLogin').success(function(res){
callback(res);
});
},
login:function(user, callback){
$http.post('api/auth/login', user).success(function(res){
callback(res);
});
},
logout:function(callback){
$http.get('api/auth/logout').success(function(res){
callback(res);
});
}
};
});
I'm using the same in my controller like this
$scope.isLogin = false;
$scope.UserData = {};
$scope.login = function(user){
Auth.login(user, function(res){
if(res.status){
$scope.isLogin = true;
$scope.loginBoxShown = false;
$scope.UserData = res.data;
$location.path('/Dashboard');
}
});
};
Its working fine on first run but once I reload the page the variable $scope.isLogin
and $scope.UserData
are reset to their default value.
Is there any way to store them in a global scope permanently before my $scope.logout();
function delete them.