I am new to AngularJs and I just started learning about routing and partial templates. I'm writing a little application that is trying to do routing and inserting a partial templates into the layout HTML page when you click on a specific hyperlink such as Home, about or contact.
However, I'm having difficulty understanding why my templates are not loading into the layout view. I researched Stack Overflow and other resources and nothing seems to work. The structure of my files is like this:
index.html file
Templates Folder:
+home.html
+about.html
+contact.html
Scripts folder:
+script.js
+angular-route.min
Following is my code: index.html:
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
<title>Routing App Example</title>
<script src =
"https://code.angularjs.org/1.5.6/angular.js">`
</script>`
<script src = "https://code.angularjs.org/1.5.6/angular-route.js">`</script>
<script type="text/javascript" src = "Scripts/script.js"></script>
</head>
<body ng-app = "RoutingApp" ng-controller = "MainController">
<header>
<div>
<ul>
<li><a href = "#/home">Home</a></li>
<li><a href = "#/about">About</a></li>
<li><a href = "#/contact">Contact</a></li>
</ul>
</div>
</header>
<div>
index ng-root
<ng-view></ng-view>
</div>
</div>
</body>
</html>
script.js:
var RoutingApp = angular.module('RoutingApp', ['ngRoute']);
RoutingApp.config(['$routeProvider', '$locationProvider', '$scope', function($routeProvider, $locationProvider){
$routeProvider
// route for the index page
// route for the addOrder page
.when('/home', {
templateUrl: 'Templates/home.html',
controller: 'HomeController'
})
.when('/about', {
templateUrl: 'Templates/about.html',
controller: 'AboutController'
})
// route for the showOrders page
.when('/contact', {
templateUrl: 'Templates/contact.html',
controller: 'ContactController'
})
.otherwise({
redirectTo: '/home',
});
}]);
RoutingApp.controller('MainController', function($scope){
$scope.message = "Welcome from the MainController";
});
RoutingApp.controller('HomeController', function($scope){
$scope.message = "Welcome from the HomeController";$scope
});
RoutingApp.controller('AboutController', function($scope){
$scope.message = "Welcome from the AboutController";
});
RoutingApp.controller('ContactController', function($scope){
$scope.message = "Welcome from the ContactController";
});
home.html
<h1>{{message}}</h1>
about.html
<h1>{{message}}</h1>
contact.html
<h1>{{message}}</h1>
The problem that I'm having is the fact that the partial templates are not loading into the layout view page. I don't know what I'm doing wrong.