Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies

My main module definition:

angular.module('app', ['app.animators', 
                       'app.places', 
                       'app.orders', 
                       'app.excursions', 
                       'app.events', 
                       'app.hotel', 
                       'app.controllers', 
                       'app.services',
                       'angular-img-cropper',
                       'ui.router', 
                       'templates', 
                       'ngResource', 
                       'ngCookies', 
                       'ui.bootstrap', 
                       'ngImgCrop', 
                       'angularjs-dropdown-multiselect', 
                       'uiGmapgoogle-maps'])
  .config(['$httpProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider', ($httpProvider, $locationProvider, $stateProvider, $urlRouterProvider) ->
    $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')

    $urlRouterProvider.otherwise("/admin/home")

    $stateProvider.state('admin.services'
      url: '/services'
      controller: 'ServicesController'
      templateUrl: 'services.html'
    ).state('admin.home'
      url: '/home'
      templateUrl: 'home.html'
    ).state('signIn'
      url: '/admin/signin'
      controller: 'SignInController'
      templateUrl: 'signin.html'
      resolve:
        user: ['authService', '$q', (authService, $q) ->
                $q.reject({ authorized : true }) if authService.currentUser()
        ]
    ).state('admin.signOut'
      url: '/signout'
      controller: 'SignOutController'
    ).state('404'
      url: '/404'
      templateUrl: '404.html'
    ).state('admin'
      abstract: true
      url: '/admin'
      template: '<ui-view />'
      resolve:
        user: ['authService', '$q', (authService, $q) ->
                $q.reject({ unAuthorized : true }) unless authService.currentUser()
              ]
    )

    $locationProvider.html5Mode(true)
])

Also in index.html is <script src="/assets/angular-cookies/angular-cookies.js?body=1">. I get the error in this module:

angular.module('app.services', []).factory('authService', ['SIGN_IN_ENDPOINT', 'SIGN_OUT_ENDPOINT', '$http', '$cookies', (SIGN_IN_ENDPOINT, SIGN_OUT_ENDPOINT, $http, $cookies) ->
    auth = {}
    auth.signIn = (credentials) ->
        return $http.post(SIGN_IN_ENDPOINT, { user: credentials })
    auth.signOut = ->
        return $http.delete(SIGN_OUT_ENDPOINT)
    auth.currentUser = ->
        $cookies.remember_token

    auth
]).value('SIGN_IN_ENDPOINT', "#{ location.protocol }//#{ location.host }/sign_in").value('SIGN_OUT_ENDPOINT', "#{ location.protocol }//#{ location.host }/sign_out")
.factory("httpErrorInterceptorModule", ["$q", "$rootScope", "$location", ($q, $rootScope, $location) ->
  success = (response) ->
    return response;

  error = (response) ->
    if(response.status is 401)
      $location.path('/admin/signin')
      return $q.reject(response)

  return (httpPromise) ->
    return httpPromise.then(success, error)
]).config(["$httpProvider", ($httpProvider) ->
  $httpProvider.responseInterceptors.push("httpErrorInterceptorModule")
])

Error is: Error: [$injector:unpr] Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies <- authService

What I do wrong? AngularJS version is 1.2.25.

like image 540
malcoauri Avatar asked Jun 16 '15 05:06

malcoauri


2 Answers

angular-cookie.js version must have the same version that angular.js

"//code.angularjs.org/X.Y.Z/angular-cookies.js" where X.Y.Z is the AngularJS version you are running.

like image 81
Михаил Семахин Avatar answered Oct 15 '22 00:10

Михаил Семахин


If you use angularJs version 1.3 use angular-cookies 1.3.17!

In my project i have the same problem! So i did a downgrade!

like image 23
Mateus Moura Avatar answered Oct 14 '22 23:10

Mateus Moura