Created
February 23, 2015 14:03
-
-
Save mbildner/90a128a662cedc79d1c2 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<title>angular js todo</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.13/angular.min.js"></script> | |
</head> | |
<body ng-app="todoApp"> | |
<div ng-controller="TodoListController"> | |
<h2>Todo Items</h2> | |
<ul> | |
<li ng-repeat="item in todoItems track by $index"> | |
<p>{{item}}</p> | |
<button ng-click="removeItem($index);">remove</button> | |
<button ng-click="finishItem($index);">finish</button> | |
</li> | |
</ul> | |
<input ng-model="itemLabelModel"> | |
<h2>Finished items</h2> | |
<ul> | |
<li ng-repeat="item in finishedItems track by $index"> | |
<p>{{item}} | |
</li> | |
</ul> | |
<button ng-click="addNewItem(itemLabelModel);">Add Item</button> | |
</div> | |
<script> | |
// make the angular application | |
var application = angular.module('todoApp', []); | |
application.controller('TodoListController', function ($scope) { | |
// initialize empty values | |
$scope.todoItems = []; | |
$scope.finishedItems = []; | |
$scope.itemLabelModel = ''; | |
$scope.addNewItem = function (itemLabel) { | |
// add new item | |
$scope.todoItems.push(itemLabel); | |
// clear old input | |
$scope.itemLabelModel = ''; | |
}; | |
$scope.finishItem = function (itemLabel) { | |
var finishedItem = $scope.todoItems.splice(itemLabel, 1)[0]; | |
$scope.finishedItems.push(finishedItem); | |
}; | |
$scope.removeItem = function (itemLabel) { | |
// remove todoItem from our array | |
$scope.todoItems.splice(itemLabel, 1); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment