-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Infinite $digest() loop AngularJS with filter expression on html attribute #15874
Comments
FWIW: I've edited your plunkr to reproduce the issue with an easier filter syntax. I guess it doesn't matter, but I wanted to drop it here just to be sure:
A |
The issue with filtered arrays in component bindings is discussed here #14039 |
I'm interested to see how to implement a workaround using |
One quick workaround is to use |
Yep, that did solve the plunkr I added: https://plnkr.co/edit/4czmVoTGz1YvM63IrPqs?p=preview Out of curiosity: Anything available regarding the |
Thinking about it now :-) |
I think this is actually a bug - we are getting stuck in a state where it is testing |
Isn't this intended behavior? |
If this is intended, I think it's odd to see the UI work but the console error out. |
This is also expected behavior when there is an infinite digest error. We exit the digest loop to avoid freesing the browser. The error doesn't mean that there is something wrong with your app, except that some binding/watcher is constantly changing. In this case, the change doesn't matter, since the two array are identical (even if not pointing to the same reference), so it is expected that your app continues to work as expected. |
But I don't think we should hit an infinite loop here. Why is the array identity changing? |
Because of the filter, no? |
OK, so the filter always returns a new object and the one-way binding only tests for object identity equivalence. So it is expected behaviour. Here is a reasonable workaround (IMO), which could be tailored to the specific needs of the situation for best performance: https://plnkr.co/edit/g0AzLUAbwfiiIl8PNgcE?p=preview
We should document this. |
I am pretty sure this will break if you have more than one |
Thanks, @petebacondarwin, would using |
@jbedard previously wondered if this could be handled in $parse directly: #14039 (comment) |
This should also be fixed by #16553 which adds one-way collection watching ( |
Would be nice if we have one-time bindings in component and directive definition too, like "::<" or "<::" like we can use inside templates |
That would be cool indeed 😃 Right now, only the user of the component/directive has control over whether the binding is normal or one-time (which makes sense since they know whether the value can change). But it would be cool if the component/directive author could also have control, because oftentimes components/directives do to react to binding value changes, so there is no point in keeping the watcher active (but the user doesn't have to know about this). @wilker7ribeiro, could you create a separate issue about this. |
Two ways you could do this today:
|
Duplicate of #16173, right? |
Indeed. And I'm afraid I'll have to agree with myself 😁 |
I'm submitting a ...
Current behavior:
When I create a filter expression on an html attribute, an attribute that is later bounded incoming in a component and used inside an
ng-repeat
, it triggers an infinite digest cycle/loop. The output comes up fine on the screen, but there are errors in the console suggesting that it triggers and infinite digest cycle. Code to reproduce is on a plnkr: http://plnkr.co/edit/JdiLEIyji2pHd3eeNMUL?p=preview.This also happens when the array I'm passing is an array of literals such as number or string (http://plnkr.co/edit/mfjPgZjBro39Nb7WYpjU?p=preview).
Expected / new behavior:
Minimal reproduction of the problem with instructions:
Here's a plnkr with the code in action http://plnkr.co/edit/JdiLEIyji2pHd3eeNMUL?p=preview - open the devtools in your browser to see the errors appear.
Angular version: 1.5.* and 1.6.1/2/3
Browser: [all]
Anything else:
Error message
Possible solutions
<todo-list todo-items="$ctrl.todoItems" filter-by="{completed:true}"></todo-list>
. For full source see here: aredfox/todo-angularjs-typescript@e71900b. But I feel it's working around the problem, plus I don't understand why this triggers a $digest() cycle and why it shouldn't just work.Related issue
The text was updated successfully, but these errors were encountered: