NaN error in angular when adding amounts

0

I have a function in angular which me suma the amount that happens with the parameter, but throws me at the end of the suma error Nan , which can be ?, this total is plasmo in html , I hope for your help, thanks!

In another function, I invoke the sum_total , since in my html I have a list with ckeck box , then the following function selects all the records, and therefore I have that sumar all the amounts of each one of the registers, the problem is that I print each sum and make it perfect, the problem is the last one throws the NaN

Select all

here we invoke the function sum_total

$scope.seleccionar_todo = function () {
        $scope.cuentas.forEach(function (cuenta) {
            cuenta.pagar = $scope.seleccionado;
            $scope.sum_monto(parseFloat(cuenta.importe_total));
        });
    };

feature that totals all amounts

$scope.monto_total=0;

    $scope.sum_monto = function (importe){
        $scope.monto_total= parseInt($scope.monto_total) + parseInt(importe);
        console.log(parseInt($scope.monto_total));
    };
html
<h4 style="margin-left:990px; ">Monto Seleccionado: {{ monto_total }}</h4>
    
asked by Jonathan Garcia 23.08.2018 в 17:32
source

1 answer

0

The error was that it sends a null value, which I do not tend because, I pass an undefined value to the function, the answer is like this

$scope.monto_total=0;

    $scope.sum_monto = function (importe){
        if(importe!==undefined){
            $scope.monto_total = parseFloat($scope.monto_total) + parseFloat(importe);
            console.log(importe + " - " + parseFloat($scope.monto_total));
        }
    };
    
answered by 23.08.2018 в 18:13