0
votes

I have created a service in angularjs which seems fine to me but when I inject $cookieStore into the service it gives me an uncaught error and I dont know why this is occurring.

Error:

angular.js:36Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr?p0=%24%24cookieReaderProv…ieReader%20%3C-%20%24cookies%20%3C-%20%24cookieStore%20%3C-%20loginService

Service file:

myApp.factory('loginService',  ['$q','$http','API_SERVER','$cookieStore',function ($q, $http, API_SERVER,$cookieStore) {
         var login = function(username,passowrd){
         // some code
    },

         var logout = function(username,passowrd){
          //some code
    }


         return {

                    login: function (username, password) {
                        return login(username, password);
                    },

                    logout: function (username, token) {
                        return logout(username, token);
                    },

                };

            }]);

If I remove $cookieStore then it works properly. But including the code above throws the error. Also if I add $scope to service it throws an uncaught error.

app.js:

var myApp = angular.module('myApp', ['ngRoute',
    'ui.bootstrap',
    'ngCookies',
    'ngResource',
    'ngSanitize',
])

index.html

<script src='{% static "js/angular.min.js" %}'></script>
<script src='{% static "js/ui-bootstrap-tpls-0.11.2.min.js" %}'></script>
<script src='{% static "js/angular-route.min.js" %}'></script>
<script src='{% static "js/angular-animate.min.js" %}'></script>
<script src='{% static "js/angular-resource.min.js" %}'></script>
<script src='{% static "js/angular-cookies.min.js" %}'></script>
<script src='{% static "js/angular-sanitize.min.js" %}'></script>
2

2 Answers

3
votes

It's probably a version mismatch. Make sure all of your angular JS modules match. (please post the versions of angular-cookies & angular). With that being said you say you are using 1.5x, but your error is clearly 1.2.x

-- original answer:

You should be injecting $cookies versus $cookieStore

Documentation for $cookies. $cookieStore has been deprecated.

0
votes

Angular 1.5.6 (latest angular 1):

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

https://docs.angularjs.org/api/ngCookies/service/$cookieStore