I have been trying to write the todo mvc application in angular but I have got stuck with the filtering. What I am trying to filter is todos which are completed/Active or show all. I have a variable that is called isCompleted which I'm trying to filter by. The strange thing is that it seems to work when I filter to get the completed but when I try to show the Active it shows both Active and completed. I have been trying to set data-ng-repeat="todo in todos | filter: {isComplete: false}" but it still shows all my todos. Any ideas on what I am doing wrong?
<section id="main" data-ng-cloak="">
<input type="checkbox" id="toggle-all" data-ng-model="toggleAll" data-ng-click="markAll(toggleAll)" />
<ul id="todo-list">
<li data-ng-repeat="todo in todos | filter: selectFilter()" data-ng-class="{completed: todo.isCompleted}">
<input type="checkbox" class="toggle" data-ng-model="todo.isCompleted" />
<label>{{todo.title}}</label>
<button class="destroy" data-ng-click="removeTodo(todo)"></button>
</li>
</ul>
function TodosController($rootScope, $scope, $location) {
$scope.location = $location;
$scope.$watch('location.path()', function (path) {
$scope.selectFilter = function () {
if (path == '/active') {
return { isCompleted: false };
}
else if (path == '/completed') {
return { isCompleted: true };
}
else
{
return null;
}
};
});
if (!$rootScope.todos) {
$rootScope.todos = [{ title: "todo1", isCompleted: true }, { title: "todo3", isCompleted: true }, { title: "todo2", isCompleted: false }];
//$rootScope.todos = [new Todo('Todo1', true), new Todo('Todo4', true), new Todo('Todo2', true), new Todo('Todo3', false)];
}
...