Angular + Moment
by Ganesh
HTML
<script src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/1.7.2/moment.min.js"></script>
<div ng-controller="TestController">
<strong>This will update, but it takes a minute to show any real difference...</strong>
<p>{{date | fromNow}}</p>
</div>
JavaScript
var testApp = angular.module('testApp', []);
testApp.controller('TestController', ['$scope', '$timeout', function ($scope, $timeout) {
$scope.date = new Date();
var refreshDates = function () {
$timeout(refreshDates, 30000);
};
refreshDates();
}]);
testApp.filter('fromNow', ['$window', function ($window) {
return function (dateString) {
return $window.moment(new Date(dateString)).fromNow()
};
}]);
angular.element(document).ready(function () {
angular.bootstrap(document, ['testApp']);
});