1

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?

1 Answer 1

1

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']); 
Sign up to request clarification or add additional context in comments.

3 Comments

ouch, looks like we got there at the same time :-) how does this work, should someone, and I don't mind doing it, remove their answer?
Thanks. By making these changes the Uncaught Error went away. But now its giving me this error - XMLHttpRequest cannot load file:///Users/agarwala/Desktop/Personal%20Work/AngularJS/routes/view1.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
@munna for make it working you need to host your code on some server like wamp/ISS

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.