I have my angularJS application which works perfectly when i browse it, i was trying to configure express but only the main page displays and on click of the hyperlinks i am loading partial views but the partial views is not being loaded. I get connection refused error in the browser.
Folder structure is:
app --routes.js
node_modules
public
js --app.js
views --1.html --2.html --3.html
index.html(Main Page)
server.js
Server.js
var express = require('express');
var app = express();
var mongoose = require('mongoose');
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public');
require('./app/routes')(app);
app.listen(port);
exports = module.exports = app;
routes.js
app.get('*', function(req, res) {
res.sendfile('./public/index.html');
});
app.get('/:name', function (req, res) {
var name = req.params.name;
res.render('public/views/' + name + '.html');
});
app.js
var sampleApp = angular.module('sampleApp',['ngRoute']).config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
// home page
.when('/', {
templateUrl: 'views/1.html',
controller: 'MainController'
})
.when('/nerds', {
templateUrl: 'public/views/2.html',
controller: 'NerdController'
})
.when('/geeks', {
templateUrl: 'public/views/3.html',
controller: 'GeekController'
});
$locationProvider.html5Mode(true);
} ]);
Please let me know what needs to be done to make it work.
Thanks, Sajesh
Sorry my bad...i replaced templateUrl: 'public/views/2.html' with templateUrl: 'views/2.html' and it started working