Angular 1.4.5 : Uncaught Error: [$injector:modulerr] ngRoute
Asked Answered
B

3

6

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

angular.js:38 http://errors.angularjs.org/1.4.5/$injector/modulerr?
p0=myApp&p1=Error%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.5%2Fangular.min.js%3A19%3A381)

I have a simple module with a dependency of ngRoute:

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

app.config(function ($routeProvider) {

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

})

.when('/second',{
    templateUrl : 'pages/second.html',
    controller : 'secondController'
})


});

and my html code:

<html ng-app='myApp'>
<head><title>The title</title></head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5
/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js">               
<script src="app.js"></script>
</script>
<body>

<div ng-view>
</div>


</body>


</html>
Bellbird answered 14/9, 2015 at 19:30 Comment(2)
You should check is your page has any http 400 error. Looks like the angula-route.js has not been loaded.Tilden
need closing script tag after ng-route and remove the extra closing tag after app.js. Is that a line break after /1.4.5?Hardener
F
9

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="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js"></script>          
<script src="app.js"></script>
Flabellum answered 14/9, 2015 at 19:35 Comment(2)
@Hardener Thanks for heads up dude.. :)Flabellum
@Hardener you did the other part of the answer..Thanks :)Flabellum
D
0
var app = angular.module("myApp", ["ngRoute"]);
app.config(function( $routeProvider ) {
    $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"
    });
});
Denominationalism answered 26/11, 2016 at 21:4 Comment(0)
R
0

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'
}) 
Rockyrococo answered 28/11, 2018 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.