0

Hi I am working on the angular js 60ish min tutorial an am not able to figure out the routing functionality here is my code Issue: When I open the html file nothing happens i do noy see any routing happening view1.html and view2.html are in the same folder with main.html and angular.min.js file.

Please point the mistake in the code or how to debug this.

<!DOCTYPE HTML>
<HTML data-ng-app ="demoapp">
<head><title>New angular js app </title></head>
<body>
<div>
<div ng-view></div>
</div>
<script src = "angular.min.js"></script>
<script>
var demoapp = angular.module('demoapp',[]);
demoapp.config(function($routeProvider){
$routeProvider
    .when('/view1',
        {
        controller:'SimpleController',
        templateUrl:'view1.html'
        })
    .when('/view2',
        {
        controller:'SimpleController',
        templateUrl:'view2.html'
        })
    .otherwise({ redirectTo:'/view1'}); 
});
demoapp.controller('SimpleController', function  ($scope){
$scope.customers = [
    {name:"ishan", city:"Delhi"},
    {name:"Ankit", city:"New Delhi"},
    {name:"subhash", city:"haridwar"},
    ];
$scope.addCustomer = function()
{
    $scope.customers.push
        ({
            name:$scope.newCustomer.name, 
            city:$scope.newCustomer.city
        });
};
});
</script></body></html>
2
  • what is your angular version? Commented Mar 19, 2014 at 17:18
  • AngularJS v1.3.0-beta.1 Commented Mar 19, 2014 at 17:31

3 Answers 3

2

Since Angular 1.2 you have to include the route module.

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

See the docs

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

2 Comments

It did not help. AngularJS v1.3.0-beta.1
1

Please open console on your browser to detect the errors. If any error is shown, you try to refer to the AngularJS Google CDN latest as follows:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>

After this, if your code still isn't working fine, please turn on the Debug script on your browser to investigate more.

Please let me know if any problem still happens.

Hope this will help you!!

Comments

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

don't forget Include the angular-route.js in your page

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.