hellouworld
hellouworld

Reputation: 605

One time binding called infinitely many times. Why?

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?

Upvotes: 0

Views: 128

Answers (1)

georgeawg
georgeawg

Reputation: 48968

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

Upvotes: 2

Related Questions