我开发了一个角度1.4.8应用程序,我的登录mechanisme工作得很好但我有一个错误,是会话似乎未保存,除非我刷新页面, 这是我的代码:
.state('dashboard', {
url:'/dashboard',
controller: 'HomeController',
templateUrl: 'partials/dashboard/main.html',
resolve:{
auth: function($q, authenticationSvc) {
var deferred = $q.defer();
var userInfo = authenticationSvc.getUserInfo();
if (userInfo) {
deferred.resolve(userInfo);
} else {
deferred.reject({ authenticated: false });
}
return deferred.promise;
}
}
这是控制器:
authenticationSvc
.login(credentials.username, credentials.password)
.then(
function(response){
sessionFactory.setData(response.token);
$state.go('dashboard.home');
},
function(error){
$rootScope.errorLogin = "Login failed , please verify your login/password.";
$rootScope.showLoginFailedAlert = true;
}
);
最后,这是sessrionFactory:
function sessionFactory($window, $rootScope){
return {
setData: function(value){
$window.sessionStorage["pallas_token"]= value;
$rootScope.token = value;
},
getData: function(){
return $window.sessionStorage["pallas_token"]
},
clearData:function(){
$window.sessionStorage.removeItem("pallas_token");
}
};
}
我错了什么?我真的很困惑。