[javascript] Failed to instantiate module error in Angular js

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

This question is related to javascript angularjs

The answer is


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

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

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


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.


For me the solution was fixing a syntax error:

removing a unwanted semi colon in the angular.module function


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.


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.


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.