0

I have an ng-repeat and inside that ng-repeat i have

<p style="color:red">Booked Ref : {{agencyref(contentzz.Ref)}}</p>

With the way angular works it's constantly running the function, but that function has a HTTP request inside it, i just want to run it once. Is there something else i can use?

3 Answers 3

1

You're able to use the one-time binding syntax (::).

When using one-time binding the expression will only be evaluated once. After evaluation the watcher will be removed, thus the output of the expression will not be updated the next time the digest cycle is being triggered

Using one-time binding:

<p style="color:red">Booked Ref : {{::agencyref(contentzz.Ref)}}</p>

More info in docs: https://docs.angularjs.org/guide/expression#one-time-binding

Sign up to request clarification or add additional context in comments.

3 Comments

Still seems to be continuing
i get this error : Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! [phonegap] Watchers fired in the last 5 iterations: []
Now I realized that this actually dont work on expression. I will update answer soon.
1

If you wish to run this just once, why do you want to include it in ng-repeat?

Suggestion 1 : I suggest you can use ng-init in the parent tag and use the result later.

Suggestion 2 : You can make use of .run method of your angular module, however this is a very specific requirement. With your current question I am not sure if this will fit you or not, but this is another way of executing the method just once.

2 Comments

Thanks for your answer, i'm quite new to angular ive not been able to impliment either of these suggestions, could you please expand a little on the ng-init?
i dont want to run it once, i want to run it once for each repeated item
-1

Use this

<p style="color:red" ng-if="$first">Booked Ref : {{agencyref(contentzz.Ref)}}</p>

So, this will get executed for the first element only.

1 Comment

I want to run the function on every element but only once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.