私は Angular.js に頭を悩ませようとしていますが、私が抱えている 1 つの問題を解決できないようです。
次のコードがあります。
'use strict';
angular.module('authValidator',['ngCookies', 'ngResource']).factory('$authValidator', ['$cookieStore', '$http', function($cookieStore, $http){
return {
setUserToken: function(token){
$cookieStore.set('currentUserToken', token);
},
userToken: function(){
$cookieStore.get('currentUserToken');
},
loggedIn: function(){
return false;
},
requestAuthentication:function(username, password){
var self = this;
return $http.post('/login', {"username":username, "password":password}).then(function(response) {
self.setUserToken(data.security_token);
});
},
clearUserToken: function(){
$cookieStore.remove('currentUserToken');
}
}
}]);
私が抱えている問題は、「then」内で $cookieStore が null のように見え、その結果、次のエラーが発生することです。
Error: 'undefined' is not a function (evaluating '$cookieStore.set('currentUserToken', token)')
信じられないほど基本的なものが欠けていることは知っていますが、それを見つけることができないようです. 任意の推奨事項は大歓迎です。
ありがとう