繁体   English   中英

无法使用AngularJS访问Cookie

[英]Can't access to cookies with AngularJS

我无法访问本地主机中存储的cookie。

炊具已经存储(查看图片)

当我尝试显示时,我不确定(查看图片)

这是我显示的js代码:

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代码,从我的rest API获得结果后,我将该属性存储在cookie中。

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");

        });

};


}]);

信息存储在cookie中。 但是,当我转到另一个页面(具有不同的js文件)时,我无法获取cookie。 这是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);
}]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM