不太确定这是怎么回事,我的代码中有什么问题..只需在登录页面中成功添加cookie,但是当导航到使用相同控制器的主页时,cookie仍未定义或消失
app.js
(function () {
'use strict';
angular.module('app', ['ngCookies']);
})();
在服务中添加Cookie
$cookieStore.put('account_id', data.items.Id);
$cookieStore.put('account_type', data.items.Type);
控制器
angular.module('app', ['AuthService', 'ngCookies'])
.controller('AuthController', ['$scope', '$http', 'AuthService', '$cookies', '$cookieStore', function ($scope, $http, AuthService, $cookies,$cookieStore,$state, $window) {
// reed cookies
$scope.go = function () {
var temp = $cookieStore.get('account_type');
alert(temp);
}
}]);
从html调用go()
<body class="hold-transition skin-blue sidebar-mini" ng-app="app">
<div class="wrapper" ng-controller="AuthController">
<header class="main-header" data-ng-init="go()">