Reputation: 55
I´m trying to use orderBy within a ng-repeat but it´s not working.
This is where I create and populate the array used on the ng-repeat:
for (var k = 0; k < $scope.allUsers.length; k++)
{
var score =
{
points: 0,
headshot: 0,
winners: 0,
};
$scope.currentScore.push(score);
}
And here is where I call it:
<tr ng-repeat="singleScore in currentScore | orderBy: 'points'">
<td>{{singleScore.points}}</td>
<td>{{singleScore.headshot}}</td>
<td>{{singleScore.winners}}</td>
</tr>
This "currentScore" array is changed from time to time in a setInterval function and its values are being correctly updated.. but the orderBy never works.
I know there are a lot of similar questions but almost all are resolved with "you are not using an array".. but I am indeed using an array and it´s still not working.
What am I doing wrong?
EDIT: Solved with:
$interval($scope.calculateWeekScore, 2000, 10, true, $scope.activeWeek);
Thanks!
Upvotes: 1
Views: 79
Reputation: 24583
setInterval is not called in angular's scope. You will need to call $scope.apply()
You can also use angularjs $interval, which is wrapper around setInterval.
https://docs.angularjs.org/api/ng/service/$interval
Upvotes: 1