lundi 29 décembre 2014

formatting custom filter for moment.js


Vote count:

0




I have the below code for moment JS. The logic is if its less than 30 days from now, show as fromNow() which should returns mins or hours or days ago. Otherwise it should just return as MMM YYYY.


However I am getting the error "undefined is not a function".


The date data format is ok (its a series of numbers) and works when I do manual filter as such {{ post.timestamp | formatdate: "MMM YYYY" }}




The filter logic is as below.



app.filter('formatdate', function() {
var result = function (date, formatstring){
if(moment(date).fromNow().days() < 30) {
return moment(date).fromNow();
}
return moment(date).format("MMM YYYY");
}
return result;
});




and the html



{{ post.timestamp | formatdate }}


asked 39 secs ago







formatting custom filter for moment.js

Aucun commentaire:

Enregistrer un commentaire