0

I have an array of objects where most of the parameters are functions that are passed different parameters. Is it possible to use Angular's orderBy filter with these properties? One variation of what I've tried that's not working:

<tr ng-repeat="warrior in warriors | orderBy: dps(vm.orderTarget)">
    <td>{{warrior.name}}</td>
    <td>{{warrior.dps(vm.target1)}}</td>
    <td>{{warrior.dps(vm.target2)}}</td>
    <td>{{warrior.dps(vm.target3)}}</td>
</tr>
2
  • What is vm? Can you explain it more? Commented Jan 12, 2017 at 5:59
  • Most best practices say to use controllerAs and never $scope, and vm is a very common default for controllerAs, standing for 'view model.' Commented Jan 12, 2017 at 21:19

1 Answer 1

1

Try this tricky solution:

<tr ng-attr-temp="{{warrior.temp=warrior.dps(vm.orderTarget)}}" ng-repeat="warrior in warriors | orderBy: 'temp'">
    <td>{{warrior.name}}</td>
    <td>{{warrior.dps(vm.target1)}}</td>
    <td>{{warrior.dps(vm.target2)}}</td>
    <td>{{warrior.dps(vm.target3)}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

1 Comment

Like a charm, thanks. Now to see how to change the sorting stat and reverse them!

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.