Ashish K Agarwal
Ashish K Agarwal

Reputation: 1172

AngularJS Routes example giving Uncaught Error: [$injector:modulerr]

I am completely new to Angular JS. I am using Angular JS version 1.3.15 Here is the code I wrote for routes. However I am getting the following exception in google chrome -

   Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=app&p1=Error%3A%20…wala%2FDesktop%2FPersonal%2520Work%2FAngularJS%2Fangular.min.js%3A38%3A135

The code is -

<html ng-app="app">
<head>
<title>Sample Angular JS application - routes example</title>
<script src="angular.min.js" type="text/javascript">
</script>

<script>
 var app = angular.module('app',[]);

  app.config(function ($routeProvider) {
       $routeProvider
       .when('/', {
             controller : 'SimpleController',
             templateUrl : 'routes/view1.html'
          })
       .when('/view2', {
             controller : 'SimpleController',
             templateUrl : 'routes/view2.html'
          })
        .otherwise({
             redirectTo: '/'
          });
    });

     app.controller('SimpleController',['$scope',
         function ($scope) {
              $scope.customers = [
                 {name: 'Akshay Kumar' , city: 'Chandigarh'},
                 {name: 'Madhuri Dixit' , city: 'Mumbai'},
                 {name: 'Shah Rukh Khan' , city: 'Delhi'},
                 {name: 'Anil Kumble' , city: 'Bangalore'},
                 {name: 'Rishi Kanitkar' , city: 'Pune'},
                 {name: 'Dhanraj Pillai' , city: 'Pune'}
               ];

               $scope.addCustomer = function() {
               $scope.customers.push(
                {
                    name: $scope.newCustomer.name , 
                    city: $scope.newCustomer.city
                });
           }
        }]);
       </script>
     </head>

     <body> 
        <div>
        <!-- Placeholder for the views -->
        <div ng-view=""></div>
       </div>
     </body>
    </html>

How can I solve this error?

Upvotes: 1

Views: 464

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

You missed couple of things here

  1. Script reference of angular-route.min.js
  2. You are missing ngRoute in your app declaration

Code

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

Upvotes: 1

Related Questions