Angularjs routing not working

yellowbyte picture yellowbyte · Apr 18, 2014 · Viewed 66.7k times · Source

Everything worked fine until I tried to add routing. I read that Angularjs version 1.2+ requires 'ngRoute' as an dependency (I am using version 1.2.16). I added it but it still doesn't work. Below are my codes.

test.html (Main Page)

<html ng-app="demoApp">
<head>
    <title></title>
</head>
<body>
    <p>Front Page</p>
    <div ng-view></div>
    <script src="angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.js"></script>
    <script src="testjs.js"></script>
</body>
</html> 

testjs.js

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

demoApp.config(function ($routeProvider) {

    $routeProvider.when('/', {
        controller: 'SimpleController',
        templateUrl: '/partials/first.html'
    });

});

var controllers = {};
controllers.SimpleController = function ($scope){
    $scope.first = "Info";
    $scope.customers=[
        {name:'jerry',city:'chicago'},
        {name:'tom',city:'houston'},
        {name:'enslo',city:'taipei'}
    ];
};
demoApp.controller(controllers);

first.html

<div>
    <input type="text" ng-model="name"/>
    </br>
    {{first}}
    </br> 
    <ul>
        <li ng-repeat="cust in customers | filter:name">{{cust.name | uppercase}} - {{cust.city}}</li>
    </ul>   
</div>

Answer

Yoeri picture Yoeri · Apr 18, 2014

Here is the most basic setup possble, I'll try to make another one with your code: http://plnkr.co/edit/sN9TagVBOdX3mkrxaTiu?p=preview

EDIT updated with the sample code. Everything seems to be working?

EDIT 2 the problem is OP wasn't running a webserver. Ng-Route needs a webserver to function properly.