The most Angular-ly thing to do is create a directive:
app.directive("minutesAgo", function($interval) {
var MINUTE = 60000;
function updateMinutes(scope) {
scope.minutes = Math.floor((Date.now() - new Date(scope.startTime)) / MINUTE);
scope.pluralizedMinutes = scope.minutes < 1 ? "Less than a minute" :
scope.minutes +
(scope.minutes == 1 ? " minute" : " minutes");
}
return {
restrict: "AE",
scope: {
startTime: "="
},
template: "<span>{{pluralizedMinutes}} ago</span>",
link: function(scope, element) {
updateMinutes(scope);
$interval(function() {
updateMinutes(scope);
}, MINUTE);
}
};
})
This can be used inside an element with a controller that specifies a timestamp like so:
<minutes-ago start-time="timestamp"></minutes-ago>
You can try it out on Plunker.