Reputation: 4452
I am new to the MEAN Stack. I tried out something pretty basic in html with some angularJS which is working when I open it in my browser. But unfortunately the code is not working anymore when I try to render it with my nodeJS server. The index.html is shown but the angular part is not working anymore. My output is just {{article}}. Do you have any suggestions ?
index.html
<html ng-app="ibrahimsBlog">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ibrahims Blog</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="articleController">
<div ng-repeat="article in articles">
{{article}}
</div>
</div>
</body>
</html>
app.js
var app = angular.module('ibrahimsBlog', [])
app.controller('articleController', [
'$scope',
function($scope) {
$scope.articles = [
'foo',
'bar',
'baz'
];
}]);
And my pretty basic node server:
var express = require('express'), app = express();
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(3000, function() {
console.log('Server listening on port 3000');
});
Upvotes: 2
Views: 2990
Reputation: 9454
Change SERVER.JS to:
var express = require('express');
var app = express();
/* ==========================================================
serve the static index.html from the public folder
============================================================ */
app.use(express.static(__dirname + '/public'));
app.listen(3000, function() {
console.log('Server listening on port 3000');
});
Upvotes: 5