Error: [$ injector: modulerr]

I am newbie. Just learn / try to integrate Angular with my webapp (Java + jQuery + requireJS). I do not use any router, and below is my script. From the other https://stackoverflow.com/a/312716/112, I found out that this error is due to the lack of inclusion of the ngRoute module. Starting with version 1.1.6 this is a separate part. But in my lower code, I am not using ngRouter at all. When I do not refer to this, why do I get this error?

Error: [$ injector: modulerr] Unable to instantiate module because of: [$ injector: nomod] Module 'counter' is not available! You either mistakenly wrote the name of the module, or forgot to load it. If registering a module ensures that you specify the dependencies as the second argument. http://errors.angularjs.org/1.2.11/ $ injector / nomod? p0 = counter

Template:

<ul ng-app="counter" ng-controller="counterController"> <li> <span class="ui-button-text" ng-bind="critical"></span> </li> <li> <span class="ui-button-text" ng-bind="error"></span> </li> <li> <span class="ui-button-text" ng-bind="warn"></span> </li> <li> <span class="ui-button-text" ng-bind="note"></span> </li> </ul> 

Js

 requirejs.config({ paths : { angular: "/js/lib/angular/angular.min" }, shim : { "angular": { deps: [ "jquery"], exports: "angular" } } }); require(["angular", "jquery"],function() { var module = angular.module('counter', []); module.controller('CounterController', function ($scope, $http, $timeout) { $scope.critical = 0; $scope.error = 0; $scope.warn = 0; $scope.note = 0; function setData(d){ $scope.critical = d.critical; $scope.error = d.error; $scope.warn = d.warn; $scope.note = d.note; } var getCounters = function() { var config = {headers: { 'X-MY-Request': (new Date()).getMilliseconds() } }; $http.get('xxxxxxx', config) .success(function(data, status, headers, config) { setData(data); $timeout(getCounters, 60000); }).error(function(data, status, headers, config) { // Handle the error }); } $timeout(getCounters, 500); }); 
+6
source share
4 answers

In your template, the name of your controller has a lowercase initial letter counterController . Your js has an uppercase counterController . Could this be a problem?

Any module entered that is not found will throw an error. Not just ngRoute.

Edit

I just threw the quick plunker together and without β€œdemanding” that all your code be right. This way you have nothing to lose in your angular code. All modules work.

Therefore, the problem should be related to the "require" setting. I literally never used it, so I could not help you. Check out more Angular + Requirejs here - Downloading in the wrong order .

For now, if I were you, I would learn one technology at a time. Just download the angular and jquery resources and then find out how to use them. Then, when you feel a little more comfortable, add "require".

+3
source

Had the same problem in order to get additional error information by calling the bootstrap function using {debugInfoEnabled: true} as follows:

 angular.bootstrap(document.getElementById('app-root'), ['MyApp'], {debugInfoEnabled: true}); 

This will print to the console what underscore module that cannot instantiate.

+1
source

If $injector:modulerr appears in your test environment, you may need to include the module in your test environment. For me it was karma and phantoms that needed to be included in: test / karma.config.js

0
source

I encountered this error and my root module of the application did not load.

In the end, I reordered the list of dependencies and the error when you left.

Hope this helps someone. Spend me an hour!

0
source

All Articles