Why is this the only mandatory behavior, as if it weren't there?

I can't seem to figure out how it works. My actual application logic is too complex for a plunker, but I can't even get a simple script like http://plnkr.co/edit/ka57xquoR2ZdY2F0li76 to work in my application.Here is a plunker of my exact code down to the file structure. I removed all the stuff from the application to get the simplest one-off example of binding to work - it works in the plunter, but not in my code.

I am using AngularJS 1.3.0-rc.4

Here is a snippet of what's in plunker

{{::current.text}}
<br />
{{current.text}}
<br />
<input ng-model="current.text" type="text" />
<br />

      

In my application, both are updated {{::current.text}}

and {{current.text}}

when the textbox is updated ...

Is there something that can be disabled or one-time binding or is preventing scope variables from settling so that ontime interception can occur?

+3


source to share


3 answers


It turned out it was Batarang (angularjs chrome debug extension) that was causing this behavior. My guess is that persistent monitoring does not allow the scope variable to be changed and hence the one-time binding does not fire.



+21


source


As Richard Hermanson pointed out, you will have to remove any html that is not related to this error until you have enough subset to understand what is causing it.

If you need a random guess, perhaps the element bound once is contained by an element that itself rebuilds in the DOM, so bind-once is reinitialized each time.

for example



<div ng-if="someOndition">
  <div>{{::current.text}}</div>
</div>

      

Every time an ng-if goes from false to true, its internal html is recompiled and added to the DOM. This may not be exactly your problem, but the only thing I could see was to recompile the directive.

+2


source


A slightly different case I ran into is an expression that returns a result that is somehow tied to the current time in milliseconds, long enough to return a different result for each of the possible multiple calls in the digest loop.

In my case, although the one-time bound expression would be marked for deregistration at the end of the current digest cycle, the expression was re-evaluated multiple times during the same digest cycle as far as I could gather. This caused the digest iteration limit to be exceeded and caused error messages in the console log to be preempted like this:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: 
[[{"msg":"fn: oneTimeWatch","newVal":"1475668099352","oldVal":"1475668099346"}],
 [{"msg":"fn: oneTimeWatch","newVal":"1475668099356","oldVal":"1475668099352"}],
 [{"msg":"fn: ...

      

In my particular case, ensuring that the expression always returned the same value for a given input after the first call for that input allowed the one-time binding to work properly. A bit counter-intuitive, so it got me caught, but maybe it's useful to someone!

0


source







All Articles