27

I encountered the following error with a root cause of Module 'ngRoute' is not available

Uncaught Error: [$injector:modulerr] Failed to instantiate module Amail due to:

Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:

Error: [$injector:nomod] Module 'ngRoute' 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."

Javascript code :

var amailServices = angular.module('Amail',['ngRoute']);
function emailRouteConfig($routeProvider) {
$routeProvider.
    when('/', {
        controller: ListController,
        templateUrl : 'list.html'}).

    when('/view/:id',{
        controller : DetailsController,
        templateUrl:'detail.html'}).

    otherwise({
        redirectTo:'/'
    });
}
amailServices.config(emailRouteConfig);

How to fix this

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51

6 Answers6

47

You need to include angular-route.js in your HTML:

<script src="angular-route.js">

http://docs.angularjs.org/api/ngRoute

CD..
  • 72,281
  • 25
  • 154
  • 163
  • 1
    I got this error after moving from angularjs 1.1.5 to 1.2. As I found from another page, this is because ngRoute is no more part of core angularjs. So, not only you have to include angular-route.js in the html (or bundles), you also have to inject ngRoute in angular.module(). – newman Mar 12 '14 at 01:15
  • 1
    I have the same error when I try to use 'ngWebcam', I already included the script in my index.html and injected it to my angula.module() and I still have the error. Pls help – JkAlombro Apr 04 '17 at 01:08
2

Or the minified version of the file...

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

More information about this here:

"This error occurs when a module fails to load due to some exception. The error message above should provide additional context."

"In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x, be sure that you've installed ngRoute."

Listed under section Error: $injector:modulerr Module Error in the Angularjs docs.

maudulus
  • 10,627
  • 10
  • 78
  • 117
1

For me the solution was fixing a syntax error:

removing a unwanted semi colon in the angular.module function

Mirza Vu
  • 1,532
  • 20
  • 30
1

I got this error due to not pointing the script to the correct path. So make absolutely sure that you are pointing to the correct path in you html file.

Robby Lebotha
  • 1,211
  • 11
  • 9
1

For me the error occurred due to my browser using a cached version of the js file containing the module. Clearing the cache and reloading the page solved the problem.

TM00
  • 1,330
  • 1
  • 14
  • 26
0

Such error happens when,

1. You misspell module name which you injected.
2. If you missed to include js file of that module.

Sometimes people write js file name instead of the module name which we are injecting.

In these cases what happens is angular tries to look for the module provided in the square bracket []. If it doesn't find the module, it throws error.

Rakesh Burbure
  • 1,045
  • 12
  • 27