0

I use ng-repeat to display a list of tasks:

<div class="task_container" ng-repeat="task in tasks | orderBy:weigth(task)">
    <span >Task:<span><br><span>{{task.label}}</span>
</div>

Each task has some properties, and I have defined a weight function that sums up these properties:

function weight(task)
{
    var weight_value = task.priority - task.difficulty + task.interest;
    return weight_value;
}

However, when displaying the page, the tasks are not ordered at all.

Is there a better/correct way to achieve that ?

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169

1 Answers1

1

Just do that :

<div class="task_container" ng-repeat="task in tasks | orderBy:weigth">
    <span >Task:<span><br><span>{{task.label}}</span>
</div>

A jsFiddle here : http://jsfiddle.net/pkozlowski_opensource/zjvsu/1/

Another complete post here : Custom sort function in ng-repeat

And attach your weight function to the $scope

Community
  • 1
  • 1
Thomas Pons
  • 7,709
  • 3
  • 37
  • 55