Angular 1.4.5 : Uncaught Error: [$injector:modulerr] ngRoute

All we need is an easy explanation of the problem, so here it is.

When I try to refresh the page I have this error :


I have a simple module with a dependency of ngRoute:

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

app.config(function ($routeProvider) {

.when('/', {
    templateUrl :'pages/main.html',
    controller : 'mainController'


    templateUrl : 'pages/second.html',
    controller : 'secondController'


and my html code:

<html ng-app='myApp'>
<head><title>The title</title></head>
<script src="
<script src="">               
<script src="app.js"></script>

<div ng-view>



How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Basically its typographical mistake.

It should be

<html ng-app='myapp'>

Instead of

<html ng-app='myApp'>

Additionally correct your script tags like below.

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

Method 2

var app = angular.module("myApp", ["ngRoute"]);
app.config(function( $routeProvider ) {
    .when("/home", {
        template : "<h1>Main</h1><p>Click on the links to change this content</p>"
    .when("/red", {
        templateUrl : "red.htm"
    .when("/green", {
        templateUrl : "green.htm"
    .when("/blue", {
        templateUrl : "blue.htm"

Method 3

In my case I used $routeProvider.when({}) without url as first parameter and that was the case, when I add the url like below, error was gone.

$routeProvider.when('/post/:id', {
   templateUrl: 'views/post.html',
   controller: 'PostController'

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply