Really stuck here so will appreciate the help.
Let me explain my set up/stack first:
- Backend - Node with Express
- Frontend - Angular
Snippet from the Node part of the code:
var router = express.Router();
router.get('/main', function(req, res){
res.render('wall', {siteTitle:'Home'});
});
Snippet from the HTML page:
<p>{{ siteTitle }}</p>
<div ng-controller="wallPosts">
<div ng-repeat="post in posts">
<p>{{ post.title }}</p>
</div>
<div>
Snippet from the Angular controller:
var angularApp = angular.module('angularApp', []);
angularApp.controller('wallPosts', ['$scope', '$http', function($scope, $http){
$http.get('/api/posts')
.success(function(result){
$scope.posts = result;
console.log(result);
})
.error(function(data, status){
console.log(data);
});
}]);
Okay so here is the problem - {{ post.title }} bit in the HTML page is not getting updated. However, this is: {{ siteTitle }}
The difference - post.title comes from the Angular app whereas the siteTitle comes from the res.render from Node.
Also, the console.log in the Angular controller works as I wanted to rule out there being a problem with the connection. Also, I have ruled out the '/api/posts' API call as it does indeed pass on an array of objects.
I have configured my Node to use 'hogan-express' as below:
Snippet from Node:
app.engine('html', require('hogan-express'));
So - can someone help me out here? What am I doing wrong? I want my Node to do the routing plus act as an API server and Angular just to get the data from the APIs and just chuck them out to the HTML page.
Thanks in advance, Shayan