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.