Created
July 19, 2012 14:56
-
-
Save lalabear/3144505 to your computer and use it in GitHub Desktop.
邊學AngularJS邊做Todo List第三回
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
function TodoCrtl($scope) { | |
$scope.newItem = ''; | |
$scope.todoList = []; | |
$scope.addItem = function(){ | |
if(this.newItem){ | |
this.todoList.push({label:this.newItem}); | |
this.newItem = ''; | |
} | |
} | |
} | |
function TodoCrtlRemovable($scope) { | |
$scope.newItem = ''; | |
$scope.todoList = []; | |
$scope.addItem = function(){ | |
if(this.newItem){ | |
this.todoList.push({label:this.newItem,isFinish:false}); | |
this.newItem = ''; | |
} | |
} | |
$scope.removeItem = function(item){ | |
item.isFinish = true; | |
} | |
} |
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
<!DOCTYPE html> | |
<html ng-app> | |
<head> | |
<meta charset="utf-8"> | |
<title>邊學AngularJS邊做Todo List (3)</title> | |
<script type="text/javascript" src="http://code.angularjs.org/angular-1.0.1.min.js"></script> | |
<script type="text/javascript" src="js/controllers.js"></script> | |
</head> | |
<body ng-controller="TodoCrtlRemovable"> | |
<h1>Todo List</h1> | |
<form ng-submit="addItem()"> | |
<input type="text" ng-model="newItem" name="newItem" /> | |
<input type="submit" id="submit" value="新增待辦事項" /> | |
</form> | |
<ul id="todo"> | |
<li ng-repeat="item in todoList | filter:{isFinish:false}"> | |
<input type="checkbox" ng-click="removeItem(item)"> | |
{{item.label }} | |
</li> | |
</ul> | |
<hr> | |
<h1>Finished!</h1> | |
<ul id="finish"> | |
<li ng-repeat="item in todoList | filter:{isFinish:true}"> | |
{{item.label}} | |
</li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment