Playing around with routing in AngularJS but I can't seem to get it working correctly. Trying to display some templates with different controllers for each, but it seems to only route to one of them.
Plunker link: https://plnkr.co/edit/6nupjElxdxWR8Ov7f59n?p=preview
Here is the code:
index.html
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<div class="container">
<div id="menu">
<a href="#">Home</a>
<a href="#page1">Page1</a>
<a href="#page2">Page2</a>
</div>
<div id="mainContent">
<div ng-view></div>
</div>
</div>
</body>
</html>
script.js
app = angular.module('myApp', ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: "base.html",
controller: "homeController"
})
.when('/page1', {
templateUrl: "page1.html",
controller: "pageController"
})
.when('/page2', {
templateUrl: "page2.html",
controller: "pageController"
});
});
app.controller('homeController', [
'$scope',
function homeController($scope) {
console.log("Home");
}
]);
app.controller('pageController', [
'$scope',
function pageController($scope) {
console.log("Page");
}
]);
base.html
<div>Base</div>
page1.html
<div>Page1</div>
page2.html
<div>Page2</div>
Currently, it seems to only show the base.html template no matter what button is pressed.