Created
June 19, 2015 01:28
-
-
Save nuweb/0d16779a3e6b242145d0 to your computer and use it in GitHub Desktop.
AngularJS Todo App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("myApp", []) | |
.controller("TodoCtrl", ["$scope", function($scope){ | |
// clear input todo text | |
$scope.lastTodoClass = "odd"; | |
$scope.todoText = ""; | |
// default todos | |
$scope.todos = [ | |
{text:'Learn AngularJS', done:false, class:"even"}, | |
{text: 'Build an app', done:false, class:"odd"} | |
]; | |
// get total todos | |
$scope.getTotalTodos = function () { | |
return $scope.todos.length; | |
}; | |
// add a todo | |
$scope.addTodo = function () { | |
var todoClass = $scope.lastTodoClass==="odd" ? "even" : "odd"; | |
$scope.lastTodoClass = todoClass; | |
$scope.todos.push({text:$scope.todoText, done:false, class: todoClass}); | |
$scope.todoText = ''; | |
}; | |
// clear completed todos | |
$scope.clearCompleted = function () { | |
$scope.todos = $scope.todos.filter(function(todo) { | |
return !todo.done; | |
}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment