JB's
JB's

Reputation: 626

Routes in Angular Not working

Code

<body ng-app="ngapp">
<h2>NG App</h2>
<div>
    <ng-view></ng-view> 
</div>
<script src="Scripts/angular.min.js"></script>
<script>
    var app = angular.module('ngapp', ["ngRoute"]);
    app.config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'Page1.html',
                controller: 'simpCtrl'
            })
            .when('/view2', {
                templateUrl: 'Page2.html',
                controller: 'simpCtrl'
            });
    });
    app.controller('simpCtrl', function ($scope) {
        $scope.customers = [
            { name: 'Jack', age: 10 },
            { name: 'Abdul', age: 12 },
            { name: 'Zubair', age: 11 },
            { name: 'Ammar', age: 10 }
        ];
    });
</script>

I have registered the routes properly but its is not working, I don't know why. Any Idea how to debug or find misbehaving code in angular?

Page1.html

<div>
<h2>View 1</h2>
Customer Name: 
    <input type="text" ng-model="search.name" />
<ul>
    <li ng-repeat="n in customers | orderBy:'name' | filter:search:strict ">{{n.name|uppercase}} - {{n.age}}
    </li>
</ul>
<a href="#/Page2.html">View 2</a>

Thanks

Plunker link to code

Upvotes: 1

Views: 107

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

There are few issues with your application,

(i) You are refering to angular2 library, change it like this

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>

(ii) you have not added reference for ngRoute

 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.4/angular-route.js"></script>

Working Application

Upvotes: 3

Related Questions