【发布时间】:2015-01-12 21:45:25
【问题描述】:
在我的 Angular 应用程序中,我使用 $http 通过 REST API 调用登录到应用程序的后端。
当我登录应用程序时,后端返回一个保存用户登录状态的 Cookie。我想将此 cookie 信息存储在某处,以便我可以通过 Angular 应用程序检查用户是否已登录(这可能会影响他被定向到的页面等)。
为了说明,这是我的登录服务代码:
loginRsrc.factory('loginSrvc', ['$http',
'URLs', //defined in 'Constants'
function($http, URLs){
var signInURL = URLs.HOST + "/api/signIn";
return function(userEmail, userPassword){
console.log("Logging In...");
return {
execute: function(){
return $http({
method: 'POST',
url: signInURL,
data: $.param({email: userEmail, password: userPassword}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
}
};
}
}]);
如何访问 Cookie 并在收到时“拦截”它,以便我可以将其状态存储在一个变量中以便稍后检查和/或更新(即在注销时)?
【问题讨论】:
标签: javascript angularjs cookies angular-http