Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm facing a problem in which my views are n't showing the values on the main page. I am trying to create a SPA(Single Page Application) using Angular JS.

I've kept the three html pages (main,about and blog).html in a separate folder named pages.

Everytime I run this application the contents written in three html pages (main,about and blog).html invisible to me..


Kindly re-view my code and tell me what's my mistake

What I have tried:

My main page(index.html)

<!DOCTYPE html>







<title>




<h1>Home</h1>
<h3>{{message}}</h3>


<h1>Blog</h1>
<h3>{{message}}</h3>


<h1>About</h1>
<h3>{{message}}</h3>

Home
Blog
About













My script page

var app = angular.module('myApp', ['ngRoute']);

app.config(function ($routeProvider) {
$routeProvider

.when('/', {
templateUrl: 'pages/home.html',
controller: 'HomeController'
})

.when('/blog', {
templateUrl: 'pages/blog.html',
controller: 'BlogController'
})

.when('/about', {
templateUrl: 'pages/about.html',
controller: 'AboutController'
})

.otherwise({ redirectTo: '/' });
});


app.controller('HomeController', function ($scope) {
$scope.message = 'Hello from HomeController';
});

app.controller('BlogController', function ($scope) {
$scope.message = 'Hello from BlogController';
});

app.controller('AboutController', function ($scope) {
$scope.message = 'Hello from AboutController';
});



my home.html page

Home



{{message}}





my blog.html page

Blog



{{message}}



my about.html page

About



{{message}}

Posted
Comments
Karthik_Mahalingam 23-Aug-17 0:02am    
add the code inside < pre > tag

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