Angular Js Infinite Digest Loop

joburgbeardcompany

Active Member
Joined
Nov 23, 2016
Messages
68
I wonder if anyone can help me.

I'm playing around with angular and I'm building a one page order form that will eventually send an email with the order summary.

But every time I click on a checkbox, it logs an error in the console - infinite digest loop.

Can anyone see why it's doing that?

Thank you in advance. Here's the Code Pen

http://codepen.io/mustacheza/pen/KWyxrK
 

_kabal_

Executive Member
Joined
Oct 24, 2005
Messages
5,922
the line causing the problem is the binding in your tempate to R{{ sumRows(product.variation) }} inside the ng-repeat

Code:
ng-repeat="product in selectedProducts"

sumRows calls setSelectedProducts, which in turn calls $scope.selectedProducts = selectedProducts;

this then causes the ng-repeat to run again, which then causes R{{ sumRows(product.variation) }} to run, over and over.


I would generally recommend not binding to functions.

on a side note, I recommend you reading https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md


using $scope should generally be avoided.


why start learning angularjs? angular (ie angular 2 or 4 or whatever you want to call it) is stable, and the recommend track

angular CLI makes it super easy to get started
 
Last edited:

joburgbeardcompany

Active Member
Joined
Nov 23, 2016
Messages
68
Hi,

Thanks for your reply!

I'm not really sure how else to do it? Would you mind helping me with that small part?
 
Top