2

THE SITUATION:

I need to use cookies in my Angular App. I have followed what should be the proper steps to properly setup the ngCookies module in my app, but somehow it isn't working.

This is the error message i am getting:

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

THE STEPS:

These are the steps i have done:

  1. bower install angular-cookies
  2. Choose first option in bower:

     angular#1.3.13 which resolved to 1.3.13 and is required by angular-animate#1.3.13, angular-sanitize#1.3.13, ionic#1.0.0
    
  3. In index.html include:

    <script src="lib/angular-cookies/angular-cookies.min.js"></script>

  4. Include the module ngCookies:

    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCookies'])
    
    angular.module('starter.controllers', ['ngCookies'])
    
  5. Inject the service in the controller:

    .controller('MainCtrl', function( $scope, $rootScope, $cookies ) 
    

VERSIONS -- EDIT

I thought the issue could be related with versions since these were the previous versions:

Angular version: 1.3.13
Angular-cookies version: 1.4.1

enter image description here

I have then reinstall angular to the latest version: #1.4.1 and reinstall angular-cookies but the issue persists with the same error message.

THE QUESTION:

How can i properly setup angular-cookies? Why i am getting that error?

FrancescoMussi
  • 20,760
  • 39
  • 126
  • 178
  • 1
    Please try once with option 3. Angular should be of latest version. And it will be backward compatible to all other plugins and existing application code. – Yashika Garg Jun 24 '15 at 09:23

3 Answers3

2

The angular packages should have the same version as the angular version you are using. So in this case you want to use 1.3.13 for angular cookies.

Angular does not use semantic versioning and is not necessarily backwards compatible.

Edit: I am not sure whether 1.4 has been released yet. If it has you could consider switching to the newer version.

1

I will give perfect solution for this same issue which is came for me at my fresher time.

How can i properly setup angular-cookies?

You have already did that pretty much. That's enough for you.

Why i am getting that error?

May be you are configure invalid structure

Don't worry about the version,I think you have configured correct versions. So Just come out from version issue.

Solutions

Please check under verifications :-

  • Have you put correct script path in your index.html screen?
  • Please put the cookie.js before your main module code run.

    like this below format

    <script src="Scripts/angular.js"></script>// angular script
    <script src="Scripts/angular-cookies.min.js"></script>// cookie script
    <script src="app/home/home.js"></script>//my sub module js for home  screen
    <script src="app/app.js"></script>// this is my main module js, here i configure the cookie
    
    • Remove installed scripts in your index page. just past this and try one more time ⌚

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-cookies.js"></script>

I hope these both verification will don for you.

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • Thank you for replying. I have doublechecked that and both the path and the order are correct.. Strange. As it is, it is supposed to work. I have been checking around and other people are having the same issue in this period. Like in this question: http://stackoverflow.com/questions/30859779/angularjs-unknown-provider-cookiereaderprovider-cookiereader-cookie It may be a current bug? – FrancescoMussi Jun 24 '15 at 10:27
  • Yes is working now! Including angular-cookies as CDN is working properly now. But the path was correct. Is because of version? don't understand yet the cause of the issue but thank you very much! – FrancescoMussi Jun 24 '15 at 11:24
0

Latest angular-cookies seem to use AngularJS v1.4.1 but by default angular installs v1.3.x. Install latest version of angular by using

bower install angular#1.4.1

Don't forget to select 3) angular#1.4.1. Hope this solves your problem.

Nabin Singh
  • 377
  • 2
  • 6
  • I have installed angular at the latest version 1.4.1 and uninstall and reinstal angular-cookies. But unfortunately there is still the same problem – FrancescoMussi Jun 24 '15 at 09:55
  • @johnnyfittizio Are you sure you have right path for the angular-cookie file? Try removing all other modules and just use ngCookies only. I created a sample repo on github. Please check at https://github.com/me-nabinsingh/cookie-issue. – Nabin Singh Jun 24 '15 at 10:10
  • Thank you very much for the efforts! I have tried what you suggest but still the issue persists. – FrancescoMussi Jun 24 '15 at 10:29
  • Can you create a new git repo and upload your file there? I will check what's wrong. – Nabin Singh Jun 24 '15 at 10:43
  • Thank you. It seems have been resolved including angular-cookies as CDN – FrancescoMussi Jun 24 '15 at 11:34