0

I have an angular-js controller returning json data from the database. I bind the returned data to the $scope.details var in the success function.

In the HTML I use the NG-REPEAT to show all the rows with the values

 <tr ng-repeat="detail in details">
    <td><span>{{detail.timestamp}}</span></td>
    <td>{{detail.T_AC}}</td>
    <td>{{detail.T_OH}}</td>
    <td>{{detail.T_AW}}</td>
    <td>{{detail.T_UD}}</td>
    <td>{{detail.T_AT}}</td>
    <td>{{here the TOTAL of all T_* should show}}</td>
 </tr>

The last field shall calculate the sum of all the detail.T_* fields (which are all integers) when I use the {{detail.T_AC + detail.T_OH}} it's not doing the actual sum, but rather glues the numbers together (eg. 1+1 shows 11 instead of 2)

The function and the controller are:

myApp.controller("databasecontroller",['$scope','$http',function($scope,$http){
 function getInfo() {
    $http.post('phpscripts/returndata.php').success(function(data) {
       $scope.details = data;
    });
 }
}]);
Jasper
  • 121
  • 8
  • Because all your data is strings. Do `parseInt(details.T_AC) + details.T_OH...` then all values will be converted int's – Justinas Apr 10 '20 at 10:53
  • Does this answer your question? [How to add two strings as if they were numbers?](https://stackoverflow.com/questions/8976627/how-to-add-two-strings-as-if-they-were-numbers) – Justinas Apr 10 '20 at 10:56
  • when I use the parseInt the stays empty, however, with this: (+detail.T_AC)+(+detail.T_OH) it seems to work..... – Jasper Apr 10 '20 at 11:13

0 Answers0