In my database, I have a value called task_time. I want to add this value to itself so that the total time is calculated as totalTime = task_time + task_time + ... + task_time.
This is how I retrieve the data:
function getEndTasks() {
$http.get('db_files/endTasksDB.php').then(function(response) {
$scope.dates = response.data;
console.log($scope.dates);
})
}
The console log displays:
Array[10] 0 : Object 1 : Object 2 : Object 3 : Object 4 : Object 5 : Object 6 : Object 7 : Object 8 : Object 9 : Object
Object 0:
Object
$$hashKey:"object:60"
deadline:"2017-02-28"
dept:"test"
id:"1"
priority:null
status:"Closed"
task:"test"
task_end:"2017-03-02 10:57:51"
task_start:"2017-02-27 14:45:53"
task_time:"83"
total_time:"null"
username:"Nelson"
This is what I have tried:
$scope.total = response.data.map(function(item) {
var totalTime = 0;
for (var i=0; i<(item.task_time).length;i++){
totalTime = item.task_time[i];
totalTime += totalTime;
item.total_time = totalTime;
console.log("total time: " +item.total_time);
}
return item;
})
No errors are thrown, but the console log displays:
total time: 88 total time: 33 total time: 99 total time: 00 etc
and here is the table where I want to display it:
<table md-table>
<thead md-head md-order="sort.order">
<tr md-row>
<th md-column>Spółka</th>
<th md-column>Łączny czas</th>
</tr>
</thead>
<tbody md-body>
<tr md-row md-select="totalTime" md-on-select="" md-auto-select ng-repeat="totalTime in total | orderBy:sort.order | filter:search">
<td md-cell>{{ totalTime.dept }}</td>
<td md-cell>{{ totalTime.total_time }} godzin</td>
</td>
</tr>
</tbody>
</table>