3

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

1
  • 1
    You routing.js should be defined after angular.js Commented Sep 11, 2013 at 9:48

2 Answers 2

4

You are running your code before Angular! Place the <script> with your code after the <script> of Angular.

Sign up to request clarification or add additional context in comments.

Comments

2

Please remove '/' from '/Templates/dashboard.html' just use Templates/dashboard.html

$routeProvider.when('/', { templateUrl: 'Templates/dashboard.html',controller:'Mycontroller' })

.otherwise({redirectTo :'Templates/otherwise.html'})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.