I am new for web development. If it is a silly question, I apologize for it. My ng-repeat shows not thing with the JSON fetched from mongodb, but it works when I pass a local JSON. I've struggled for it the whole day. Could anyone tell me what went wrong?
here is my Angular code
(function(){
var app = angular.module('app', ['ngRoute']);
app.controller('CommentController', ['$scope', '$http', function($scope, $http){
//I've tried 'this.comment', it still not work.
//It works when I use a test local JSON'this.comment = [{Visitor: 123, Comment: 345, CreateDate: 879}, {Visitor: 123, Comment: 345, CreateDate: 879}]
$scope.comment =
$http({url: 'db-comments'}).success(function (comments) {
//I've confirmed 'comments' is an array of the JSON objects which I want.
return comments;
});
}]);
})();
here is my HTML code
<div id="home" class="container" ng-controller='CommentController as comments'>
<div id="comment" ng-repeat="x in comments.comment">
<h2>{{x.Visitor}}</h2>
<hr>
<p>{{x.Comment}}<p>
<span>{{x.CreateDate}}</span>
<hr>
</div>
</div>
here is my node.js code
router.get('/db-comments', function(req, res, next){
Comment.find(function(err, data){
if(err){
console.log('can not fetch the data')
}
res.send(data);
})
});
Thanks in advance!