I'm iterating over a list with dates (jobs.submitted):
<div ng-controller="DashboardController as dashboard">
<div ng-repeat="job in dashboard.jobs | filter: {status: 'started'}" class="row">
<div class="col-xs-3">{{job.submitted}}</div>
</div>
Now I want to calculate a duration:
(new Date(job.submitted)) - (new Date(job.completed))
If I put this directly into the expression I get a syntax error (I guess angularJS doesn't understand the Date object).
If I put it into a function, the function in the controller, the function never evaluates:
{{dashboard.getDuration(job)}}
is blank.
What is the best way of tackling this?
getDurationas a property on yourjobsobject? Or is it on your controller? Isdashboardyour controller? We need more information.Dateinto$scope($scope.Date = Date) or just{{ jobs.getDuration(job) }}(assuming you didthis.jobs.getDuration = function ...)?dashboard.jobsseems to be an array, without a functiongetDurationin there. So, looks like you need to add getDuration into$scopeor intothisin your controller and then use controller As syntax.