Sunday, 9 April 2017

Angular Routing Not Working With Express

I am trying to create a single page app using Angular. routing I'm using Node/Express on the back-end. While Express is serving my static index.html correctly, my partial .html pages are not being pulled into my ng-view.

Here is my Angular routing code:

    app.config(['$routeProvider', function ($routeProvider) {

    $routeProvider
    .when("/", {
        templateUrl: "intro-header.html"
    })
    .when("/movies", {
        templateUrl: "movies.html",
        controller: "moviesCtrl"
    }).
    otherwise({
        redirect: '/'
    });
}]);

Here is my Express server.js code:

var express = require('express');
var path = require('path');
var app = express();

app.set('port', 3000);
app.use('/', express.static(__dirname + '/'));

app.use(function(req, res) {
res.sendFile(__dirname + '/index.html');
});

app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/index.html'));
});

var server = app.listen(app.get('port'), function() {
var port = server.address().port;
console.log('Running server at http://localhost:' + port + '/');
});

Thanks in advance!



via wdc_dt

No comments:

Post a Comment