0

I am trying to implement a 'remember me' option on my login page and have ventured down the path of using ngCookies to store a local cookie to handle this. However, in trying to follow the instructions from angular documentation I am unable to get the module working in my Web Application.

I am using AngularJS version 1.4.8 and have made sure my angular-cookies.min.js is running the exact same version. I have made sure to add my <link> tags in the correct order:

    <script src="../vendor/jquery/dist/jquery.min.js"></script>
    <script src="../vendor/angularjs/angular.min.js"></script>
    <script src="../vendor/angularjs/angular-cookies.min.js"></script>

However, when I try to load the module into my application:

var EdgeApp = angular.module('EdgeApp', [
    'ngCookies', 
    'ngAnimate', 
    ....
])

I get an $injector:modulerr error:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=EdgeApp&p1=Error%3A…2Fdrake-monitor%2FRestApi%2Fvendor%2Fangularjs%2Fangular.min.js%3A19%3A463)

All other modules and dependencies load correctly and work fine.

Riples
  • 1,167
  • 2
  • 21
  • 54
  • Can you show the rest of your code (like your controller)? What you've provided appears correct. – WonderGrub May 09 '16 at 23:47
  • @WonderGrub I am getting this error without even injecting anything into a controller. I have many controllers and services, etc. and everything was working fine, until I add the `'ngCookies'` module to my application. I can post my index.html file and my app.js file if you need? – Riples May 10 '16 at 00:00
  • Yeah - or maybe a jsfiddle or Plunker. It's hard to say. Is it possible that you haven't included the angular-animate.js file? – WonderGrub May 10 '16 at 00:12
  • @WonderGrub I have added a Plunker (https://plnkr.co/edit/EPKN8gtDtmKIW52dUgqH?p=catalogue). It doesn't actually work, but demonstrates all of my code from my index file and script.js. I have also included both the angular.min.js and the angular-cookies.min.js – Riples May 10 '16 at 00:42
  • Wow. There's a lot going on there. I wish I could say something jumped out at me, but nothing does. I guess my only suggestion would be to try peeling back some of the layers. If you remove ngCookies from the EdgeApp module, does it start working again? – WonderGrub May 10 '16 at 01:10
  • Yes immediately. I might try starting with a default app and only use `ngCookies` and see how that goes. Can you suggest a better method with my index page, or is that the only choice if you use a lot of modules? – Riples May 10 '16 at 01:27
  • With frameworks like Angular, it's kind of a necessary evil. However, you could bundle them before going live, which is actually a best practice anyway. Also, without knowing the design and architectural strategy, it's hard to say if they're all needed. My personal preference is to limit the use of 3rd party utilities - there are a lot of potential downsides as the app ages (performance, maintenance, scalability, etc). One other option is to try removing some of the other libs (one at a time) to see if there is a conflict with ngCookies. – WonderGrub May 10 '16 at 12:39

1 Answers1

1

Based on the advice from @WonderGrub, I stripped my project back to the bear basics and worked from the ground up.

To start with, I installed all of my external modules correctly using Bower (something I wasn't doing before), then I added one module at a time to see if I had any conflicts.

I also reverted back to using .js files instead of .min.js files for my development to help me identify errors more accurately.

I'm unsure what the actual cause of my issue was, but going through the procedures above and the advice from my initial post has worked for me without errors.

Riples
  • 1,167
  • 2
  • 21
  • 54