Last active
December 11, 2015 09:48
-
-
Save sijnc/4581957 to your computer and use it in GitHub Desktop.
This file contains 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
<!doctype html> | |
<html ng-app> | |
<head> | |
<title ng-controller="Todo">Todos ({{todos.length}})</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script> | |
<script src="todo-class.js"> | |
function Todo() { | |
this.todos = [ | |
{text:'learn angular', done:true}, | |
{text:'build an angular app', done:false} | |
]; | |
} | |
Todo.prototype.addTodo = function(todoText) { | |
this.todos.push({text:todoText, done:false}); | |
todoText = ''; | |
} | |
Todo.prototype.remaining = function() { | |
var count = 0; | |
for (var todo in this.todos) count += todo.done ? 0 : 1; | |
return count; | |
} | |
Todo.prototype.archive = function() { | |
var oldTodos = this.todos; | |
this.todos = []; | |
for (var todo in this.todos) if (!todo.done) this.todos.push(todo); | |
} | |
</script> | |
<link rel="stylesheet" href="todo.css"> | |
</head> | |
<body> | |
<h2>Todo</h2> | |
<div ng-controller="new Todo()"> | |
<span>{{remaining()}} of {{todos.length}} remaining</span> | |
[ <a href="" ng-click="archive()">archive</a> ] | |
<ul class="unstyled"> | |
<li ng-repeat="todo in todos"> | |
<input type="checkbox" ng-model="todo.done"> | |
<span class="done-{{todo.done}}">{{todo.text}}</span> | |
</li> | |
</ul> | |
<form ng-submit="addTodo()"> | |
<input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> | |
<input class="btn-primary" type="submit" value="add"> | |
</form> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment