Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
How to avoid calling a function that gets a score twice in an ng-repeat?

I have an ng-repeat div that loops over an array, and then inside that ng-repeat, I call a function that takes the element and returns a score based on it like this:

<div ng-repeat="game in games track by $index">
    <span>{{ getScore(game) }}<i class="icon ion-checkmark-bold" ng-if="!getScore(game)"></i></span>
</div>

The problem is that I call getScore() twice every ng-repeat and I was wondering if there's a way for me to change my code so I only call it once, and then pass the result to both places.

I did try using ng-init like this:

<div ng-repeat="game in games track by $index" ng-init="score = getScore(game)">
    <span>{{ score }}<i class="icon ion-checkmark-bold" ng-if="!score)"></i></span>
</div>

However, I noticed that this doesn't work, and the score result ends up being the same for all the repeats.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!