【发布时间】:2017-06-26 20:29:19
【问题描述】:
我正在使用 angularjs 登录我的网站。我的代码:
HTML:
<input type="text" ng-model="username" placeholder="Username">
<input type="password" ng-model="password" placeholder="Password" >
<button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="signin()">Sign in</button>
JS:
app.config(function($routeProvider) {
$routeProvider
.when('/', {
resolve: {
"check": function($location, $rootScope) {
if(!$rootScope.valueCookie) {
$location.path('/login');
}
}
},
templateUrl: 'home.html'
})
.when('/login', {
templateUrl: 'login.html'
})
.otherwise({
redirectTo: '/'
});
});
$scope.signin = function() {
$rootScope.valueCookie = $cookieStore.put('obj', someSessionObj);
}
我尝试做的是 cookie 解析。当cookies在浏览器中时——点击登录后,我们在“home.html”中,刷新页面后仍然有“home.html”。我的代码不起作用。 感谢您提前回答。
【问题讨论】:
标签: javascript angularjs cookies