I am attempting to load two different partials into my page. The routes seem to be working. i.e i'm redirected to #/view1 by default, which is what I want. However when Partials/View1.html is not loaded into the page, and same is true when I manually navigate to #/view2. Can't seem to figure out what I am missing.
Here is index.html:
<!DOCTYPE html>
<html ng-app="demoApp">
<head>
<title>Using AngularJS Directives and Data Binding</title>
</head>
<body>
<div>
<div ng-view>
<!-- Placeholder for views -->
</div>
</div>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script>
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/view1',
{
controller: 'SimpleController',
templateUrl: 'Partials/View1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl: 'Partials/View2.html'
})
.otherwise({ redirectTo: '/view1' });
}]);
demoApp.controller('SimpleController', function ($scope) {
$scope.customers = [
{ name: 'John Smith', city: 'Phoenix' },
{ name: 'John Doe', city: 'New York City' },
{ name: 'Jane Doe', city: 'San Francisco' }
];
$scope.addCustomer = function() {
$scope.customers.push(
{
name: $scope.newCustomer.name,
city: $scope.newCustomer.city
});
};
});
</script>
</body>
</html>
and Partials/View1.html :
<div class="container">
<h2>View 1</h2>
Name:
<br>
<input type="text" ng-model="filter.name">
<br>
<ul>
<li ng-repeat="cust in customers | filter: filter.name | orderBy: 'city'">{{ cust.name }} - {{ cust.city }}</li>
</ul>
<br>
Customer Name: <br>
<input type="text" ng-model="newCustomer.name">
<br>
Customer City: <br>
<input type="text" ng-model="newCustomer.city">
<br>
<button ng-click="addCustomer()">Add Customer</button>
<br>
<a href="#/view2">View 2</a>
</div>
And Partials/View2.html
<div class="container">
<h2>View 2</h2>
Name:
<br>
<input type="text" ng-model="city">
<br>
<ul>
<li ng-repeat="cust in customers | filter: name | orderBy: 'city'">{{ cust.name }} - {{ cust.city }}</li>
</ul>
</div>