json3 json3 - 1 year ago 89
AngularJS Question

Why isn't my route loading?

I am new to angularjs and for some reason my routes isnt working, when I click on the test link. I have rechecked my code over and over and cant seem to find the problem.

Any help would be really appreciated!

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular-route.min.js"></script>





<a href="#test">Test</a>

<div ng-view></div>

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
.when("/test", {
templateUrl : "test.html"


Answer Source

There are couple of things I wanted to point out which you have missed.

  1. You missed to kick off angular on page. You could do it by doing ng-app="myApp" as myApp module you already defined.
  2. Other thing is, you have to change your href to href="#/test", so that on click of link you will navigate to /test route
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download