Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda