Angularjs auto refresh momentjs fromnow date value


I am a new to UI development and i have to develop a page which has a number of posts with creation dates. The creation date is displayed relative to current time like ‘3 hours from now’

I refereed this link and was able to do that successfully. But i want to refresh the from now value every 30 seconds. How to do this. The author has replied

I would say you would have to take another tac, and add an additional attribute to the scope — let’s call it reply.fromNow — and update that value within the controller periodically using the moment library.

But i couldn’t make much out of it. Can someone help me out with this thing? Thank you.

Problem courtesy of: Anirudhan J


You could put something like this in your controller:

var refreshDates = function() {
$timeout(refreshDates, 30000);

Basically, it just trigger’s a $scope.$apply() every thirty seconds.


Solution courtesy of: rtcherry

View additional discussion.