Access cookies in angularJs

I can successfully use cookies on my controller like this.

angular.module('mobbr', [ 'ngCookies' ]).    

function RegisterCtrl($scope, $cookies) { }

But whenever I try to use cookies in such a service.

angular.module('mobbr.services', []);
angular.module('mobbr.services').factory('currentUser', [ 'ngCookies', function ($cookies) {}]);

I get the following error: ngCookiesProvider <- ngCookies <- currentUser.

Any thoughts on why this won't work, and how should I initialize the cookie access service?

+5
source share
2 answers

Here's what my code looks like for something like this:

angular.module('app.MyData', ['ngResource','ngCookies']).
    factory('MyService', function($resource, $http, $cookies) {
        ...
    })
+11
source

For me it worked:

module.controller('myCtrl', ['$scope', '$cookies',
        function($scope, $cookies) {
             ...........
         }
    ]);

Instead of using, ngCookiesI use $cookies. I looked at this example , but somehow it was throwing an errorUnknown provider: ngCookiesProvider <- ngCookies

+1
source

All Articles