Skip to content

Instantly share code, notes, and snippets.

@Mozartted
Created February 7, 2017 13:46
Show Gist options
  • Save Mozartted/096c91f51583cbbd5261572171a7a0d4 to your computer and use it in GitHub Desktop.
Save Mozartted/096c91f51583cbbd5261572171a7a0d4 to your computer and use it in GitHub Desktop.
app.controller('TodoController',function TodoController ($scope,$routeParams,$filter,store){
//the todo controller would be handling new additions to the
//todo list and applying these to the DB via node and $resource
'use strict';
var self=this;
store.get();
var todos = $scope.todos = store.todos;
$scope.newTodo = '';
$scope.editedTodo = null;
$scope.$watch('todos', function () {
$scope.remainingCount = $filter('filter')(todos, { completed: false }).length;
$scope.completedCount = todos.length - $scope.remainingCount;
$scope.allChecked = !$scope.remainingCount;
}, true);
// Monitor the current route for changes and adjust the filter accordingly.
$scope.$on('$routeChangeSuccess', function () {
var status = $scope.status = $routeParams.status || '';
$scope.statusFilter = (status === 'active') ?
{ completed: false } : (status === 'completed') ?
{ completed: true } : {};
});
self.newTask = ' ';
$scope.addTodo = function()
{
var newTask={
title:$scope.newTask.trim(),
completed:false
};
store.insert(newTask)
.then(function success(reponse) {
$scope.todos.slice()
})
.finally(function () {
self.saving = false;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment