1

I'm getting the following error and I cannot understand why. I tried my best to change/check the origin of the error, but for me everything seems to be correct. And this error happens only in production, in development it works fine.

#error
Uncaught Error: [$injector:modulerr] Failed to instantiate module recipeApp due to:
Error: [$injector:nomod] Module 'recipeApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

#app.js
var mod = angular.module('recipeApp',[]);

#application.js
//= require jquery
//= require jquery_ujs
//= require pixel-admin.min
//= require app

#config/initializers/productio.rb
config.assets.compile = false
config.assets.precompile =  ['*.js', '*.css']
config.assets.js_compressor = Uglifier.new(:mangle => false)
config.assets.js_compressor = :uglifier


#app/views/layout/application.html.erb
<body class="theme-default no-main-menu main-navbar-fixed" ng-app="recipeApp">

and when I check the source via firebug, I can see recipeApp in both js and html

I'm using

  • Rails 4.1.5
  • Angularjs 1.2.13

UPDATE

For routing I'm using ui.router, how ever I tried to add that as well, but still the same

#app/views/layouts/application.html.erb
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script> 

in my

app/assets/javascripts/app.js

'use strict';
angular.module('recipeApp',["ui.router"]);
0

2 Answers 2

6

I also ran into this issue and found the solution here: https://teamgaslight.com/blog/4-lessons-learned-doing-angular-on-rails. Thought I'd share for anyone that runs into this issue even though this question is fairly old.

Rails in production automatically minifies variables which messes up Angular.

So in config/environments/production.rb, add this line before end:

 config.assets.js_compressor = Uglifier.new(mangle: false)

Your app needs to be on Rails 4+

Sign up to request clarification or add additional context in comments.

1 Comment

Well, it works.. At least it does not throw error anymore.. but at what cost? 50% more data to load?
0

Uncaught Error: [$injector:modulerr] This error occurs when you not supplied ngRoute dependency in newer versions of angular.

You have to provide ngRoute dependency in your module as it's separate module in new angular versions.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-route.min.js"></script>

var app = angular.module('recipeApp', ['ngRoute']);

1 Comment

thanks for the answer, I tried that and still getting the same error. and however Im using 'ui-router', but even after adding it , still its the same error, Please see my update answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.