Search code examples
htmlcssangularjsmeanjs

How To Totalsum Two Values In Angularjs?


I am using MEAN stack in my application with AngularJS as my front-end. How to total sum two values in angularjs , actually we have two tables and I got the total sum values like 124.10 in convertion rate then I'M expecting to calculate convertion rate totalsum values like A + B as a 124.10 + 124.10 answer = 248.20...My Plunker.

  • We have two table so I want to calculate first table convertion rate total sum value and second table convertionrate totalsum value

  • For exmaple:- fisrt table convertion rate is 124.10, and second table convertion rate is 124.10 , we need to calculate these to value in third table like A + B answer should be 248.20.

  • I have given the plunker as reference plunker please any one knows the solution help us.

My Controller:-

  .filter('sumOfValue', function () {
    return function (data, key) {
        debugger;
        if (angular.isUndefined(data) && angular.isUndefined(key))
            return 0;        
        var sum = 0;

        angular.forEach(data,function(v,k){
            sum = sum + parseFloat(v[key]);
        });        
        return sum.toFixed(2);
    }
})

My Data:-

$scope.sryarndebitnote = [
{
"_id": "57ac1b6d82e1c5940ac3c730",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-08-11T06:30:05.118Z",
"shipment_id": "57ac19b982e1c5940ac3c72f",
"conversion_rate": "62.04",
"invoice_value_fob_currency": "Rs",
"invoice_value_fob": "300.231",
"invoice_quantity_unit": "KG",
"invoice_quantity": "37",
"invoice_date": "2016-08-17",
"supplier_name": "Msd",
"buyer_name": "Mani selvam .R"
},

{
"_id": "57b5af69df0475401f644b2e",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-08-18T12:51:53.671Z",
"shipment_id": "57b5af5bdf0475401f644b2d",
"conversion_rate": "62.06",
"exclusive": true,
"invoice_value_fob": "400.343",
"invoice_quantity": "97",
"supplier_name": "Msd",
"buyer_name": "Mani selvam .R"
},]

My Html:-

<tr ng-repeat="mani in resultValue=(sryarndebitnote)"> 
     <td >{{$index + 1}}</td>
       <td >{{(resultValue | sumOfValue:'conversion_rate' * 1) + (resultValue | sumOfValue:'conversion_rate' *1)}}</td>
         </tr>
     <tr>
        <td>sum</td>
            <td>B = {{resultValue | sumOfValue:'conversion_rate'}}</td>

         </tr>
  • Third table should be a+b calculating values and final total sum of C value like A+B value 248.20 , so the c value total sum is 496.40.

  • c total sum value `496.40.


Solution

  • Change this:

     <td >{{(resultValue | sumOfValue:'conversion_rate' * 1) + (resultValue | sumOfValue:'conversion_rate' *1)}}</td>
    

    To this:

     <td>{{((resultValue | sumOfValue:'conversion_rate')*1) + ((resultValue | sumOfValue:'conversion_rate' )*1)}}</td>
    

    The problem is parenthesis.