0

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

Error:

angular.js:38Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=app&p1=Error%3A%20%…oudflare.com%2Fajax%2Flibs%2Fangular.js%2F1.4.6%2Fangular.min.js%3A41%3A35)

I am providing my code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DEMO</title>
<link href="bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-route.js"></script>
<script src="angularuirouter.js" type="text/javascript"></script>
</head>

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

script.js:

"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();
        $timeout(function(){
          myFriend.resolve({
            hotelName: function( ) {
              return "My Friend's friend's hotel";
            },
            roomNo: function( ) {
              return "404";
            }
          });
        },5000);
        return myFriend.promise;
      }
    }
  });
} );
app.controller( "TourCoordinatorCtrl", function( $scope, accommodation ) {
  $scope.name = "Shidhin";
  $scope.place = "Switzerland";
  $scope.hotel = accommodation.hotelName( );
  $scope.roomno = accommodation.roomNo( );
} );

How can I resolve this error?

3
  • try setting route in .config instead of module definition Commented Jan 4, 2016 at 10:31
  • Try injecting $routeProvider to module definition like var app = angular.module( "app",[$routeProvider] Commented Jan 4, 2016 at 10:32
  • During development always use non-minified version of Angular. It gives exact error detail with line numbers. Commented Jan 4, 2016 at 10:36

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Missing ngRoute injection on your main module.

angular.module('app', ['ngRoute'])

Comments

0

angular.module("app",[]).config(["$stateProvider","$urlRouterProvider", function($stateProvider,$urlRouterProvider) { url routeprovider }])

Comments

0

The previous answers are correct but this can also happen when you do NOT include a Controller file. Example below shows at line 60 I had commented out the controller file but at line 13 I was actually referencing a AppCtrl. If I uncomment the line 60 the error goes away.

enter image description here

Here is what you would see on the console:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.