d4rty d4rty - 2 months ago 26
AngularJS Question

AngularJS Routing is not routing

I am trying to use the routing feature of angularJS, but so far it will not include my html templates (

user.html
and
overview.html
, which are in the same folder as
index.html
).
For information only: the expression
{{test}}
is working.

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PARA Liste</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script src="js/jquery-3.1.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-route.js"></script>
</head>

<body>
<div ng-app="angularJsApplication" ng-controller="angularJsController">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Para Liste</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="#overview">overview</a></li>
<li><a href="#user1">user1</a></li>
<li><a href="#user2">user2 - {{test}}</a></li>
</ul>
</div>
</div>
</nav>
<div class="ng-view"></div>
</div>
<script src="js/angularJsApplication.js"></script>
<script src="js/angularJsApplicationController.js"></script>
</body>
</html>


angularJsApplication.js:

var app = angular.module("angularJsApplication", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/#", {
templateURL : "overview.html"
})
.when("/overview", {
templateURL : "overview.html"
})
.when("/user1", {
templateURL : "user.html"
})
.when("/user2", {
templateURL : "user.html"
})
});


angularJsApplicationController.js:

app.controller("angularJsController", function($scope){
$scope.test = "testTestTEST";
});


user.html:

<h1>user</h1>

R.J R.J
Answer

Its typo mistake :

not templateURL It''s templateUrl

So,it should be.

templateUrl: "overview.html"
Comments