I'm trying to get my head around Angular.js and can't seem to resolve one problem that I'm having.

I have the following code:

'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');
    }
}
}]);

The problem that I'm having is that $cookieStore appears to be null inside the 'then' and as a result I encounter this error:

Error: 'undefined' is not a function (evaluating '$cookieStore.set('currentUserToken', token)')

I know there is an incredibly basic thing that I'm missing, but I can't seem to find it. Any recommendations are greatly appreciated.

Thanks

有帮助吗?

解决方案

I think the problem is that $cookieStore has a put, but no set.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top