Angularjs 1.3 One Time Binding Not Always Working

908 views Asked by At

Looking at the documentation I'm supposed to prepend :: to the expression and it should remove itself. What I don't get is why it sometimes works and sometimes doesn't.

I've created a Plunker here that 80% of the time will run all the correct oneTime $$watchListener expressions (buttons should not work).

Yet sometimes in the Launch preview in full mode it doesn't fire and the buttons change the values.

I'm posting this because I just upgraded and they fail 100% of the time on my dev environment using the code below

<div class="user-location">
  <span ng-if="::get.edit">
    <span ng-if="::user.postal">
      <span ng-bind="::user.postal"></span>
    </span>
    <span ng-if="::!user.postal">
      <span>No postal</span>
    </span>
    Edit
  </span>
  <span ng-if="::!get.edit">
    <span ng-bind="::user.postal"></span>
  </span>
</div>

Anyone else have this issue or know of a sure fire way to trigger it?

Looking at the code:

// https://code.angularjs.org/1.3.0-beta.19/angular.js line 11404
if (!parsedExpression) {
  if (exp.charAt(0) === ':' && exp.charAt(1) === ':') { // Expressions get through here
    oneTime = true;
    exp = exp.substring(2);
  }

  ...

  if (parsedExpression.constant) {
    parsedExpression.$$watchDelegate = constantWatchDelegate;
  } else if (oneTime) {
    parsedExpression.$$watchDelegate = parsedExpression.literal ? // Get through here as well but the
      oneTimeLiteralWatchDelegate : oneTimeWatchDelegate;         // $$watchDelegate method never gets called
  }

  ...
0

There are 0 answers