I am trying to learn AngularJS routing and I am facing a little problem.
I am working on a simple HTML file on my computer (which means the Url looks like file:///C:/Users ...)
I don't know what to put in the link in the /
template to make it work. I tried with home
, /home
, #home
, #/home
... But nothing seems to work.
Could you please help me ?
Here are the files : (route1.html only contains an input)
HTML file
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="js/main2.js"></script>
</head>
<body>
<div ng-view>
</div>
</body>
</html>
JavaScript File
var app = angular.module('myApp', []);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
controller: 'HomeController',
template: '<h1>Hey</h1><a href="#/home">Go to home</a>'
}).otherwise({redirectTo: '/'})
.when('/home', {
controller: 'HomeController',
templateUrl: 'route1.html'
})
}]);
app.controller('HomeController', function($scope) {
$scope.name = 'John';
});