1

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!

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

You should really use angular's $timeout, since it will perform an apply automagically
Okay, so I´m trying to use $timeout... I´ve already added it as a function to the app controller, but it´s not working. It´s simply not being called over time.. The code is edited on the main post.
Can you make a plunk or fiddle that shows your problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.