AngularJS 1.2 $injector:modulerr

JavascriptAngularjs

Javascript Problem Overview


When using angular 1.2 instead of 1.07 the following piece of code is not valid anymore, why?

'use strict';

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

app.config(['$routeProvider', '$locationProvider',
    function($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider.
        when('/', {
            templateUrl: 'part.html',
            controller: 'MyCtrl'
        }).
        otherwise({
            redirectTo: '/'
        });
    }
]);

the issue is in the injector configuration part (app.config):

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.0rc1/$injector/modulerr?p0=muninn&p1=Error%…eapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0rc1%2Fangular.min.js%3A31%3A252) 

If I remember correctly this issue started with angular 1.1.6.

Javascript Solutions


Solution 1 - Javascript

The problem was caused by missing inclusion of ngRoute module. Since version 1.1.6 it's a separate part:

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

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

Solution 2 - Javascript

my error disappeared by adding this '()' at the end

(function(){
	var home = angular.module('home',[]);

	home.controller('QuestionsController',function(){
		console.log("controller initialized");
		this.addPoll = function(){
			console.log("inside function");
		};
	});
})();

Solution 3 - Javascript

One more thing to add to the list as this is the first result that comes up with a google search of 'Error: [$injector:modulerr] angular':

If you have a mismatch between your app name in your 'index'html' and in your main javascript app definition this can also generate this error.

For example if your HTML looks like this:

    </head>
    <body ng-app="myWebSite">

        <!-- My Web Site -->
        <p>About my web site...</p>

	    etc ...

And your JavaScript looks like this (i.e has a typo on app name - myWebCite instead of myWebSite):

/** Main AngularJS Web Application */ 
var app = angular.module('myWebCite', [ 'ngRoute' ]); 

/** Configure the Routes */ 
app.config(['$routeProvider', function ($routeProvider) {   etc ...

then the 'Error:[$injector:modulerr] angular' error will be generated also.

Solution 4 - Javascript

A noob error can be forgetting to include the module js

<script src="app/modules/myModule.js"></script>

files in the index.html at all

Solution 5 - Javascript

If you have this error in console ([$injector:nomod], MINERR_ASSET:22), make sure you are not including your application code before loading AngularJS

I was doing that and once I fixed the order, the error went away.

Solution 6 - Javascript

For those using frameworks that compress, bundle, and minify files, make sure you define each dependency explicitly as these frameworks tend to rename your variables. That happened to me while using ASP.NET BundleConfig.cs to bundle my app scripts together.

Before

app.config(function($routeProvider) {
    $routeProvider.
      when('/', {
          templateUrl: 'list.html',
          controller: 'ListController'
      }).
      when('/items/:itemId', {
          templateUrl: 'details.html',
          controller: 'DetailsController'
      }).
      otherwise({
          redirectTo: '/'
      });
});

After

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider.
      when('/', {
          templateUrl: 'list.html',
          controller: 'ListController'
      }).
      when('/items/:itemId', {
          templateUrl: 'details.html',
          controller: 'DetailsController'
      }).
      otherwise({
          redirectTo: '/'
      });
}]);

Read more here about Angular Dependency Annotation.

Solution 7 - Javascript

I have just experienced the same error, in my case it was caused by the second parameter in angular.module being missing- hopefully this may help someone with the same issue.

angular.module('MyApp');

angular.module('MyApp', []);

Solution 8 - Javascript

add to link
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.0/angular-route.min.js"></script>

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

Solution 9 - Javascript

I had the same problem and tried all possible solution. But finally I came to know from the documentation that ngRoute module is now separated. Have a look to this link

Solution: Add the cdn angular-route.js after angular.min.js script

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

Solution 10 - Javascript

Another trigger for this error is leaving the "." out before your "otherwise" or any other route in your route definition:

  app.config(['$routeProvider',
     function($routeProvider) {
        $routeProvider.
           when('/view1', {
              templateUrl: 'partials/view1.html',
              controller: 'Ctrl1'
           }).
           otherwise({
              redirectTo: '/viewCounts'
           });
     }]);

Mortified by a full-stop, yet again. Gotta love JS!

Solution 11 - Javascript

Besides below answer, if you have this error in console ([$injector:nomod], MINERR_ASSET:22), but everything seems to work fine, make sure that you don't have duplicate includes in your index.html.

Because this error can also be raised if you have duplicate includes of the files, that use this module, and are included before the file with actual module declaration.

Solution 12 - Javascript

If you go through the official tutorial of angularjs https://docs.angularjs.org/tutorial/step_07

> Note: Starting with AngularJS version 1.2, ngRoute is in its own > module and must be loaded by loading the additional angular-route.js > file, which we download via Bower above.

Also please note from ngRoute api https://docs.angularjs.org/api/ngRoute

> Installation First include angular-route.js in your HTML: > >

Solution 13 - Javascript

John Papa provided my issue on this rather obscure comment: Sometimes when you get that error, it means you are missing a file. *Other times it means the module was defined after it was used. One way to solve this easily is to name the module files .module.js and load those first.

Solution 14 - Javascript

Its an injector error. You may have use lots of JavaScript files so the injector may be missing.

Some are here:

var app = angular.module('app', 
    ['ngSanitize', 'ui.router', 'pascalprecht.translate', 'ngResource', 
     'ngMaterial', 'angularMoment','md.data.table', 'angularFileUpload', 
     'ngMessages', 'ui.utils.masks', 'angular-sortable-view',          
     'mdPickers','ngDraggable','as.sortable', 'ngAnimate', 'ngTouch']
);

Please check the injector you need to insert in your app.js

Solution 15 - Javascript

My problem was in the config.xml. Changing:

<access origin="*" launch-external="yes"/>

to

<access origin="*"/>

fixed it.

Solution 16 - Javascript

Sometime I have seen this error when you are switching between the projects and running the projects on the same port one after the other. In that case goto chrome Developer Tools > Network and try to check the actual written js file for: if the file match with the workspce. To resolve this select Disable Cache under network.

Solution 17 - Javascript

After many months, I returned to develop an AngularJS (1.6.4) app, for which I chose Chrome (PC) and Safari (MAC) for testing during development. This code presented this Error: $injector:modulerr Module Error on IE 11.0.9600 (Windows 7, 32-bit).

Upon investigation, it became clear that error was due to forEach loop being used, just replaced all the forEach loops with normal for loops for things to work as-is...

It was basically an IE11 issue (answered here) rather than an AngularJS issue, but I want to put this reply here because the exception raised was an AngularJS exception. Hope it would help some of us out there.

similarly. don't use lambda functions... just replace ()=>{...} with good ol' function(){...}

Solution 18 - Javascript

I had this problem and after check my code line by line i saw this

 <textarea class="form-control" type="text" ng-model="WallDesc" placeholder="Enter Your Description"/>

i just changed it to

     <textarea class="form-control" type="text" ng-model="WallDesc" placeholder="Enter Your Description"></textarea>

and it's worked. so check your tags.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshoenView Question on Stackoverflow
Solution 1 - JavascriptshoenView Answer on Stackoverflow
Solution 2 - JavascriptarpView Answer on Stackoverflow
Solution 3 - JavascriptMickView Answer on Stackoverflow
Solution 4 - JavascriptotherDewiView Answer on Stackoverflow
Solution 5 - JavascriptJasdeep SinghView Answer on Stackoverflow
Solution 6 - JavascriptMoses MachuaView Answer on Stackoverflow
Solution 7 - JavascriptAnth12View Answer on Stackoverflow
Solution 8 - JavascriptSirajuddinLuckView Answer on Stackoverflow
Solution 9 - JavascriptBastin RobinView Answer on Stackoverflow
Solution 10 - JavascriptHilaryView Answer on Stackoverflow
Solution 11 - JavascriptpleerockView Answer on Stackoverflow
Solution 12 - Javascriptzahid9iView Answer on Stackoverflow
Solution 13 - JavascriptJoshView Answer on Stackoverflow
Solution 14 - JavascriptBipin ShilpakarView Answer on Stackoverflow
Solution 15 - JavascriptFrank ConryView Answer on Stackoverflow
Solution 16 - JavascriptShashi RanjanView Answer on Stackoverflow
Solution 17 - JavascriptAkber IqbalView Answer on Stackoverflow
Solution 18 - JavascriptAref BozorgmehrView Answer on Stackoverflow