Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda