I want to use timeago plugin to make dates look nicer. The problem is that these dates are fetched via AngularJS from the REST dynamically. So, when I attach this jQuery plugin to my page, it just doesn't process it.
So, how to better do such things? I would be happy to run without jQuery at all if possible.
I would use momentjs - http://momentjs.com/ - it has no dependencies.
Then you can just create a filter called 'timeAgo' or 'fromNow'. You should probably call it fromNow
because that's what momentjs calls it:
angular.module('myApp').filter('fromNow', function() { return function(date) { return moment(date).fromNow(); } });
Then you would just use simple data binding in your view:
<p>Pizza arrives {{pizzaArrivalDate | fromNow}}</p>
If you really wanted to use the jQuery plugin, you would probably have to write a directive. But that way of doing it is bad because it links your data to a DOM element. The way I put above seperates data from DOM which is the angular way. And it's pretty :-D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With