Reputation: 32726
I'm using entities
the format is like
{
'mongooseId': {
title: 'my title',
created: '2018-08-31T10:04:52.673Z'
}
}
and I'd like :) to put them
in descOrder by the created field
descOrder(a, b){
if(a.value.created > b.value.created){
return b.value.created;
}
}
*ngFor="let post of posts | keyvalue:descOrder"
but it doesn't work
even if I cast che string to date
new Date(a.value.created)
I change the format of the date
using Date.now() so now its a number
and with this code it works :)
descOrder(a, b){
if(b.value.created > a.value.created) {
return a.value.created;
}
}
Upvotes: 1
Views: 149
Reputation: 9687
return b.key
for that
descOrder(a, b){
if(a.value.created < b.value.created){
return b.key;
}
}
Upvotes: 1