You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
If you use JSON in an HTML attribute that is used in a '=' scope variable, it throws the error "[$rootScope:infdig] 10 $digest() iterations reached. Aborting!".
Everything seems to work fine except for this error (it seems to bind OK anyway). Just passing the attribute value as a string and calling scope.$eval within the link function seems to work, though I'm not sure if you would get 2-way data binding that way if the value was passed as an object instead of JSON.
The code should either be fixed to support inline JSON or a more explicit error should be thrown if JSON is being sent in from the attribute. If an error is thrown, it would be nice to include in the documentation on it what the work around is (scope.$eval?) and any limitations (2-way data binding broken?).
The text was updated successfully, but these errors were encountered:
The problem here is that you're creating a new object every time the watcher looks at the value, which causes $digest to think the value was dirty, which causes another $digest loop. You should assign that object to a $scope property (thereby only creating it once) or use ng-init (also creating it only once).
Thanks for responding. If you take a look at the sample code you will see that I only define the JSON once, in the HTML. The problem is that Angular (not me) is creating a new object every time the watcher looks at the value.
My suggestion is that Angular should check whether the attribute is JSON and if it is, either only process it once then store the JS object instead of the JSON string or throw an exception stating that it cannot handle JSON and how to get around it (at least this would save developers a lot of time).
http://plnkr.co/edit/VdSrFtVOj8u7ki3lP1Ef?p=preview (see script.js and web console), the thing is that although the $parse function is only created once, the populated object is actually created each time the getter is invoked.
This is typically not a problem, it's just something to be aware of
Oh, the $watcher is automatically removed if the parsed getter is a constant, as in this case... so it will only ever trigger the watch function once
When a component uses an isolate scope reference
and the the component is used with an object literal
a new object is created on every evaluation.
Therefore the compiler needs to compare
the values of the parent and the isolate scope
using object equality and not object reference
equality.
Fixesangular#5296.
jamesdaily
pushed a commit
to jamesdaily/angular.js
that referenced
this issue
Jan 27, 2014
When a component uses an isolate scope reference
and the the component is used with an object literal
a new object is created on every evaluation.
Therefore the compiler needs to compare
the values of the parent and the isolate scope
using object equality and not object reference
equality.
Fixesangular#5296.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
If you use JSON in an HTML attribute that is used in a '=' scope variable, it throws the error "[$rootScope:infdig] 10 $digest() iterations reached. Aborting!".
Here is a simple Plunker that shows the error.
http://plnkr.co/edit/B3NZSXbGsNyJec4PaFd4?p=preview
Everything seems to work fine except for this error (it seems to bind OK anyway). Just passing the attribute value as a string and calling scope.$eval within the link function seems to work, though I'm not sure if you would get 2-way data binding that way if the value was passed as an object instead of JSON.
The code should either be fixed to support inline JSON or a more explicit error should be thrown if JSON is being sent in from the attribute. If an error is thrown, it would be nice to include in the documentation on it what the work around is (scope.$eval?) and any limitations (2-way data binding broken?).
The text was updated successfully, but these errors were encountered: