Descending order by date filter in AngularJs
According to documentation you can use the reverse
argument.
filter:orderBy(array, expression[, reverse]);
Change your filter to:
orderBy: 'created_at':true
You can prefix the argument in orderBy
with a '-' to have descending order instead of ascending. I would write it like this:
<div class="recent" ng-repeat="reader in book.reader | orderBy: '-created_at' | limitTo: 1"></div>
This is also stated in the documentation for the filter orderBy.
Perhaps this can be useful for someone:
In my case, I was getting an array of objects, each containing a date set by Mongoose.
I used:
ng-repeat="comment in post.comments | orderBy : sortComment : true"
And defined the function:
$scope.sortComment = function(comment) { var date = new Date(comment.created); return date;};
This worked for me.