2015-07-01 43 views
0

我得到錯誤 - 「$ cookieStore.put不是一個函數,當我嘗試在我的應用程序中保存cookie時,我使用的是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); 
     }... 

當我試圖保存的cookies我一個得到錯誤 - 類型錯誤:$ cookieStore.put不是一個函數

我在做什麼錯

回答

2

您的參數不排隊? ...

將內聯數組註釋中的依賴關係列表與函數聲明中的參數列表進行比較。依賴關係列表必須排列(相同順序的相同依賴關係)。 (基本上,你的控制器功能試圖調用put$interval而不是$cookieStore

你有什麼...

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) { 
1

Angularjs> = 1.3

​​

您應該使用$cookies讀/寫訪問瀏覽器的cookies。

0

角版本1.3.5 ==,假設標頭值已經驗證後設置 「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... 
      } 
     }); 
相關問題