after execute the function the session created in browser. and i close and open the same browser the session will cleared.
$scope.logIn = function () {
$http(
{
method: 'post',
url: 'Service.asmx/fn_CheckLogin',
data: $.param({ strMob: $scope.login.mob, strPwd: $scope.login.pwd }),
dataType: 'json',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function (data, status, headers, config) {
sessionStorage.user = data[0].UserName;
sessionStorage.loggedIn = true;
}).error(function (data, status, headers, config) {
sessionStorage.user = '';
sessionStorage.loggedIn = false;
});
};
Answer to comment added by OP.
Yes, it is possible to execute code on document ready in your angular controller.
Append following event in you base( main) controller:
Session Storage:
MDN reference
Edit (answer to Op's comment on this answer):
To maintain information even after user closes browser, You need to user
localStorage
.Google it, it is similar to sessionStorage in usage and is easy to understand. Found this codepen to help you maybe. Still read about it and only then use it.
Also if you are open for discussion, I will suggest you to store just the username in
localStorage
and not a flag like logedIn instead maintain this information on server . Then whenever user closes browser on one system and logs in from other system and logs out. He will be logged out from all systems he has used. This is accepted behavior for most of the web applications.Use $localStorage. Here is the link: https://github.com/gsklee/ngStorage