AngularJS, $cookieStore.put 不是函数

AngularJS, $cookieStore.put is not a function

我收到错误消息 - “当我尝试在我的应用程序中保存 cookie 时,$cookieStore.put 不是一个函数。我使用的是 AngularJS 1.4.1 和相同版本的 cookie。

var examinationApp = angular.module("examinationApp", ['ngCookies']);
examinationApp.controller("examinationCtrl", ['$scope', '$window', '$http',
'$interval','$cookieStore', function ($scope, $window, $http, $cookieStore,
modalDialog){
$scope.saveTestsToCookieStore = function () {
            $cookieStore.put('answeredTests',JSON.stringify($scope.data));
            $cookieStore.put('answeredQuestions',JSON.stringify($scope.answeredTests));
            $cookieStore.put('questionStopped',$scope.currentQN);
        }...

当我尝试保存 cookie 时出现错误 - 类型错误:$cookieStore.put 不是函数。

我做错了什么?

您的参数不一致...

将内联数组注释中的依赖项列表与函数声明中的参数列表进行比较。依赖项列表必须排列(相同顺序的相同依赖项)。 (基本上,您的控制器函数试图在 $interval 而不是 $cookieStore 上调用 put

你有什么...

examinationApp.controller("examinationCtrl", [
  '$scope', '$window', '$http', '$interval','$cookieStore', 
  function ($scope, $window, $http, $cookieStore, modalDialog) {

你需要什么...

examinationApp.controller("examinationCtrl", [
  '$scope', '$window', '$http', '$cookieStore', 'modalDialog', 
  function ($scope, $window, $http, $cookieStore, modalDialog) {

Angularjs >= 1.3

The $cookieStore service is deprecated. Please use the $cookies service instead.

您应该使用 $cookies 来 read/write 访问浏览器的 cookie。

Angular version == 1.3.5 , 假设认证后在 Application Security class 中设置了 header 值 "X-AUTH-TOKEN = 'eyJwYXNzd29yZCI6ImFkbWlu'".

$scope.postData = "{\"username\" : username , \"password\": password ,\"email\" :email}";

$http({
            method: 'POST',
            url: '/API/authenticate',
            data: postData,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "X-Login-Ajax-call": 'true'
            }
        })
        .then(function(response) {
            if (response.data == 'ok') {
                $cookies['X-AUTH-TOKEN']=response.headers('X-AUTH-TOKEN');
                window.location.replace('/');
            }
            else {

                // Error Message...
            }
        });