Javascript Can';t使用AngularJS访问Cookie
我无法访问存储在localhost中的Cookie 以下是我的js代码以供显示:Javascript Can';t使用AngularJS访问Cookie,javascript,angularjs,cookies,Javascript,Angularjs,Cookies,我无法访问存储在localhost中的Cookie 以下是我的js代码以供显示: var app = angular.module("Authentification", ['ngCookies']); app.controller("log", ['$cookieStore', '$scope', '$http', function($cookieStore, $scope, $http) { $scope.typeEmploye = $cookieStore.get('type
var app = angular.module("Authentification", ['ngCookies']);
app.controller("log", ['$cookieStore', '$scope', '$http', function($cookieStore, $scope, $http) {
$scope.typeEmploye = $cookieStore.get('typeEmploye');
alert($scope.typeEmploye);
}]);
这是我的js代码,在从RESTAPI获得结果后,我将属性存储在cookies中
var app = angular.module("Authentification", ['ngCookies']);
app.controller("main", ['$cookieStore', '$scope', '$http','$location',
function($cookieStore, $scope, $http, $location) {
$scope.user = [];
$scope.type=[];
$scope.auth = function() {
$http.get("/Employe/authentification?login=" + $scope.log + "&password=" + $scope.pw)
.success(function(data) {
console.log(data);
if (data) {
$scope.user = data;
$cookieStore.put('typeEmploye', $scope.user.type);
$cookieStore.put('Authentified',true);
$scope.type=$cookieStore.get('typeEmploye');
if($scope.type == "gerant"){
window.location.href = "/Gerant/index.html";
}
else if($scope.type == "cuisinier"){
window.location.href = "/Cuisinier/index.html";
}
else if($scope.type == "servant"){
window.location.href = "/Servant/index.html";
}
else{
window.location.href = "/error";
}
}
else{
alert("Login ou mot de passe incorrects");
}
}).error(function(data, status) {
alert("Problème dans le service d'authentification");
});
};
}]);
信息存储在cookies中。但是,当我转到另一个页面(使用不同的js文件)时,我无法获取cookies。下面是js代码
var app = angular.module("ger", ['ngCookies']);
app.controller("main", ['$cookies', '$scope', '$http','$location',
function($cookies, $scope, $http, $location) {
var Type = $cookies.typeEmploye;
alert(Type);
}]);
$cookieStore
服务已弃用,您使用的angular版本是什么?好的,您是否安装了ngCookies
模块?我在html文件中导入了angular-cookies.js。该cookie不是由$cookieStore
设置的吗?我将cookies设置为:$cookieStore.put('typeEmploye',$scope.user.type);我真的无法理解这是怎么回事。