Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Angular js routing not working.

please find code below in what i hv tried section and help.

What I have tried:

My index.html below.

HTML
<!doctype html>       
<table style="font-family: Arial"><tbody><tr><td colspan="2" class="header">
	<h1>
		My Blog
	</h1>
	</td></tr><tr><td class="leftMenu">
		<a href="#/home">Home</a>
		<a href="#/courses">Courses</a>
		<a href="#/students">Students</a>
	</td><td class="mainContent">
		<ng-view>
	</td></tr><tr><td colspan="2" class="footer">
		Website Footer
	</td></tr></tbody></table>

---------------------------------------------------------
C#
var app = angular .module("Demo", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider 
.when("/home", {
	template : "Templates/home.html",
	controller: "homeController"
	})
	.when("/courses", {
		templateUrl: "Templates/courses.html",
		controller: "coursesController"
	})
});
app.controller("homeController", function($scope) {
   $scope.message="Welcome Sunny";
});
app.controller("coursesController", function ($scope) {
$scope.courses = ["C#", "VB.NET", "ASP.NET", "SQL Server"];
});
Posted
Updated 11-Feb-17 1:14am
v3
Comments
pankaj287 18-Feb-17 12:33pm    
Did you added angular.js & angular-route.js file references on your index.html page?? Also describe the error that you're getting in console.

What error you are getting?
Also can you please copy the code properly?

You can check the below link.
Tryit Editor v3.3[^]
 
Share this answer
 
v2
Change : $routeProvider
.when("/home", {
template : "Templates/home.html",
controller: "homeController"
})
To : $routeProvider
.when("/home", {
templateUrl : "Templates/home.html",
controller: "homeController"
})
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900