0

One time binding does not work in AngularJS. Why?

Here is the piece of code:

<div ng-repeat="c in ::relatedCasesInfo.hideRelations(type.cases, info) 
       | limitTo:relatedCasesInfo.initialRelationsAmount track by c.idFromFirst"
     class="initial-case-container">
    <ng-include ng-repeat="name in [c.name + (type.otherCasesArePresent || !$last || type.cases.length > relatedCasesInfo.initialRelationsAmount ? ', ' : '' )]"
        src="'dist/directiveTemplates/card/controls/relatedCases/casesContextMenu.html?v=' + $root.appVersion">
    </ng-include>
</div>

Here is the hideRelations function:

function hideRelations(relations, info) {
    return relations;
};

After running the html I see that the hideRelations is called infinitely many times. Why? What may I be missing here?

Community
  • 1
  • 1
hellouworld
  • 525
  • 6
  • 15

1 Answers1

2

The framework re-calculates because the function either returns the value undefined or the calculation is unstable.

From the Docs:

One-time binding

An expression that starts with :: is considered a one-time expression. One-time expressions will stop recalculating once they are stable, which happens after the first digest if the expression result is a non-undefined value (see value stabilization algorithm).

For more information, see

Community
  • 1
  • 1
georgeawg
  • 48,608
  • 13
  • 72
  • 95