JSFiddle - React, Tailwind, and code Playground
by jandersen
HTML
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
<h3 >Updating on an Interval</h3>
<div ng-app ng-controller="Controller" class="container">
<h4>Data</h4>
<ul ng-repeat="item in data">
<li><span>{{item.name}} {{item.duration}} ago</span></li>
</ul>
</div>
JavaScript
function Controller($scope, $timeout) {
$scope.outputs = {};
$scope.data = [
{ name: "first_field", time: new Date(), duration: '' },
{ name: "first_field", time: new Date(), duration: '' },
{ name: "first_field", time: new Date(), duration: '' }
];
function updateDurations() {
for(var i = 0; i < $scope.data.length; i++) {
$scope.data[i].duration = (new Date() - $scope.data[i].time)/1000;
}
$timeout(updateDurations, 1000, true);
};
updateDurations();
}