4

I've got template which looks like this:

<tr ng-repeat="task in tasks" class="thumbnail">
            <td ng-model="task.id">{[{ task.id }]}</td>
            <td ng-model="task.time_start">{[{ task.time_start | date : 'MMM d, y HH:mm' }]}</td>
            <td ng-model="task.time_stop">{[{ task.time_stop | date : 'MMM d, y HH:mm' }]}</td>
            <td>[here i want the time difference]</td>
            <td><button ng-click="edit(task)">Update</button></td>
        </tr>

and I want to count hours difference between task.time_stop and task.time_start. Is there anyway to do this "live", in template?

2
  • stackoverflow.com/questions/15298663/… Commented Apr 14, 2014 at 12:10
  • Why is this question marked duplicate, the problem is totally different in both.? Strange Commented Dec 8, 2016 at 5:58

1 Answer 1

5

Use the Moment library for this:

moment.utc(moment(task.time_stop.diff(moment(task.time_start))).format("mm")

You can wrap this call in a function:

$scope.timediff = function(start, end){
  return moment.utc(moment(end).diff(moment(start))).format("mm")
}

or even better create a factory for this... to make it reusable

PS: update your code to call the $scope.timediff to display the time difference:

<td>timediff(task.start,task.end )</td>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.