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

99
Views
¿Cómo evitar llamar a una función que obtiene una puntuación dos veces en una repetición ng?

Tengo un div ng-repeat que recorre una matriz, y luego dentro de ese ng-repeat, llamo a una función que toma el elemento y devuelve una puntuación basada en él de esta manera:

 <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>

El problema es que llamo a getScore() dos veces cada ng-repeat y me preguntaba si hay alguna manera de cambiar mi código, así que solo lo llamo una vez y luego paso el resultado a ambos lugares.

Intenté usar ng-init así:

 <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>

Sin embargo, noté que esto no funciona, y el resultado de la puntuación termina siendo el mismo para todas las repeticiones.

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!