I made an app with Mean framework (Angular, Express, MongoDB). User can post anything. Now I display author, title etc... but I would like to display the post date.
I tried something, and I succed to display the current date, but if I'll refresh tomorrow, the date of posts will change to tomorrow date.
This is my Post schema :
var PostSchema = new mongoose.Schema({
title : String,
link : String,
author : String,
tagg : String,
date: { type: Date, default: Date.now },
upvotes: {type: Number, default :0},
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
userliked: {type: mongoose.Schema.Types.ObjectId, ref: 'User' }
});
In my MainCtrl :
$scope.addPost = function(){
if(!$scope.title || $scope.title === ''){
return;
}
posts.create({
title : $scope.title,
link : $scope.link,
tagg: $scope.tagg,
date : $scope.date,
});
$scope.title = '';
$scope.link = '';
$scope.tagg = '';
$scope.date = '';
};
And in the HTML :
<div class="post-line" ng-repeat="post in posts | orderBy: ' -upvotes' | filter: expression" style=" padding-bottom:10px; margin-bottom:30px; background-color:rgba(0,0,0,0.02); padding:15px; box-shadow:0 2px 4px rgba(0,0,0,0.25);">
<div style="font-size:20px; margin-left:10px;display:inline;">
<span ng-show="post.link" id="target" style="display:inline;">
<a href="{{post.link}}" target="_blank"> {{post.title}}</a>
</span>
<span ng-hide="post.link" class="post-title">
{{post.title}}
</span>
<span ng-show="post.tagg" style="font-size:14px;color:rgba(0,0,0,0.5);display:block;font-style:italic;">
{{post.tagg}}
</span>
<span ng-show="post.author" style="font-size:14px;">
posted by
<span style="font-weight:bold;">{{post.author}}</span>
le
<span style="font-size:13px;">{{post.date | date:'dd/MM/yyyy'}}</span>
</span>
</div>
</div>
And of course, it doesn't display anything. Thanks by advance for your help !
EDIT :
If I make a console.log of my post object, I see the post date, but all of the posts have the same date and same hour..