miliu miliu - 5 months ago 36
AngularJS Question

AngularJS: How to get rid of "Error: 10 $digest() iterations reached. Aborting!"

I ran into this error in my project.

To illustrate it, I created a Plunker at http://plnkr.co/edit/LBXeqA5zL2dH5Zjlu6h1.

Actually, when you enter anything in search for box, there are two errors, one is

Error: 10 $digest() iterations reached. Aborting!
and the other
Uncaught Error: 10 $digest() iterations reached. Aborting!
and they seem to go together.

How to fix it?

Answer

You can't use two-way binding on your filter like that, because your filter is returning a new array each time and the digest loop goes on and on. You can get around this by sending in your items separately from your filter, and then using $watch to watch your searchString and created $scope.filteredItems dynamically. See here:

http://plnkr.co/edit/xQR6zAYM9gB7siAXPqJs?p=preview

There may be a way to send in filter and filterType together as 1, but I don't know how to do it.

And read this answer for more details: - Angular.js pass filter to directive bi-directional ('=') attribute

Comments