marjes
marjes

Reputation: 172

Error: 10 $digest() iterations reached. Aborting

hello i working with angularjs so i have a array with branch->client->invoice->details_invoice, now invoice have a total for each invoice, i do a function for sum all invoice for each client.

var TotalInvoice=0;
$scope.getSubTotal=function(indexClient,indexBranch){

            var ret="0";
            if($scope.data!=null){
                var invoice=$scope.data[0].branch[indexBranch].client[indexClient].invoice;
                if(invoice!=null){

                    for(var $i=0;$i<invoice.length;$i++){
                        if(invoice[$i].state=="3"){
                            ret=boletas[$i].amount;                             
                            TotalInvoice+=parseFloat(boletas[$i].amount);

                            }                       
                        }

                    }
            }

             return (parseInt(ret)).toFixed(2);
             }; 

and for total

   $scope.getTotalInvoice=function(){
    return (parseInt(TotalInvoice)).toFixed(2);
    };

but i have this error

    Error: 10 $digest() iterations reached. Aborting!
    Watchers fired in the last 5 iterations:

 [[.....

if i delete the line TotalInvoice+=parseFloat(boletas[$i].amount); the error disappears, please help me

update add html

<div ng-repeat="branch in company.branch| filter: { id_branch:id_b}"  >
   <tr  ng-repeat="client in branch.client.slice(page.ini,page.fin) >
 <td>{{getSubTotal(company.branch.indexOf(branch ),branch.client.indexOf(client))}}</td>
  </tr>
<tr> {{getTotalInvoice()}}</tr>
</div>

Upvotes: 0

Views: 192

Answers (1)

JB Nizet
JB Nizet

Reputation: 692121

Every time your getSubTotal() function is called, it increments the value of TotalInvoice. Since TotalInvoice is also displayed in the UI, it's watched, and its change causes getSubTotal() to be called again, which increments TotalInvoice, etc. etc.

TotalInvoice should probably set to 0 every time getSubTotal() is called. Or better, getSubTotal() shouldn't set TotalInvoice at all. That's not its job.

Upvotes: 4

Related Questions