Reputation: 39
I am trying to work out a simple example for the angular routing but its not working (it is not getting redirected to the page i expect when i browse the root directory)
HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head data-ng-app="MyApp">
<title></title>
<script src="Scripts/routing.js"></script>
</head>
<body>
Hello
<ng-view></ng-view>
<script src="Scripts/angular.js"></script>
</body>
</html>
JAVASCRIPT (routing.js)
/// <reference path="angular.js" />
var MyApp = angular.module('MyApp', [])
.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when('/', { templateUrl: '/Templates/dashboard.html',controller:'Mycontroller' })
.otherwise({redirectTo :'/Templates/otherwise.html'})
});
function Mycontroller() {
}
I am running this from Visual studio and the root url am getting in the browser is localhost:3669/ and as per my angular routing i expect this to dispaly the dashboard.html but it is not and shows only the main html page (the code i have pasted)
Any help on this will be much appreciated
Upvotes: 3
Views: 4953
Reputation: 17556
Please remove '/' from '/Templates/dashboard.html' just use Templates/dashboard.html
$routeProvider.when('/', { templateUrl: 'Templates/dashboard.html',controller:'Mycontroller' })
.otherwise({redirectTo :'Templates/otherwise.html'})
Upvotes: 2
Reputation: 40318
You are running your code before Angular! Place the <script>
with your code after the <script>
of Angular.
Upvotes: 4