Touqeer Touqeer - 5 months ago 53
AngularJS Question

Uncaught Error: [$injector:modulerr] while trying to use angular route

just try the following code and getting the error

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Routing Intro</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
<script scr="example.js"></script>

</head>
<body ng-app="mainApp">
<div ng-view></div>
</body>
</html>


here is my example.js file

var application = angular.module ('mainApp', ['ngRoute']);
application.config (function ($routeProvider){

$routeProvider
.when('/', {
template : 'Welcome User!'
})

.when('/anotherPage',{
tempalte : 'Welcome to Another page'
})

otherwise ({
redirectTo : '/'
});
});


I am getting the following error
angular.js:4458 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=mainApp&p1=Error%3A…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463)

Answer

Angular router is not a part of core angular module. You need to include it's javascript file:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.min.js"></script>
Comments