satya satya - 2 years ago 92
Javascript Question

Getting error while using ngRoute in Angular.js

I am getting the following error while using Angular.js in my app.


angular.js:38Uncaught Error: [$injector:modulerr]$injector/modulerr?p0=app&p1=Error%3A%20%…

I am explaining my code below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" ng-app="app">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="bootstrap.min.css" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src=""></script>
<script src="angularuirouter.js" type="text/javascript"></script>

<a href="#/visitplace">I want to go for a trip</a>
<div ng-view></div>
<script src="script.js"></script>


"use strict";
var app = angular.module( "app",[],function( $routeProvider ) {
$routeProvider.when( "/visitplace", {
templateUrl: "placetovisit.html",
controller: "TourCoordinatorCtrl",
resolve: {
"accommodation": function( $q, $timeout ) {
var myFriend = $q.defer();
hotelName: function( ) {
return "My Friend's friend's hotel";
roomNo: function( ) {
return "404";
return myFriend.promise;
} );
app.controller( "TourCoordinatorCtrl", function( $scope, accommodation ) {
$ = "Shidhin";
$ = "Switzerland";
$scope.hotel = accommodation.hotelName( );
$scope.roomno = accommodation.roomNo( );
} );

Please help me to resolve this error.

Answer Source

You haven't injected the ngRoute module into your app. That is why you are getting an injector error.

You must define your app like this (for example):

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

Then configure the route provider.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download