I have a list of tasks. The list starts with uncompleted tasks (task.done == false) for first followed by completed tasks. However, when I select a task and hide it as completed (task.done == true), I would like the list to be dynamically ordered and this task would be at the end of the list. Below is the example of my view controller.
app.controller ('crtl', function ($scope) {
$scope.tasks = [
{ "task":"task1", "done": false},
{ "task":"task2", "done": true},
{ "task":"task3", "done": false}
];
$scope.tasks.sort(order);
function order (x, y) {
return (x.done === y.done)? 0 : x? 1 : -1;
};
$scope.setDone = function (task) {
task.done = true;
//Como ordernar a lista dinamicamente ao alterar o booleano?
//Esta maneira não funciona
$scope.tasks.sort(order);
};
});