Skip to content

Instantly share code, notes, and snippets.

@braidn
Forked from anonymous/index.html
Created September 18, 2014 13:24
Show Gist options
  • Save braidn/d96fc5c1fdab8daeca69 to your computer and use it in GitHub Desktop.
Save braidn/d96fc5c1fdab8daeca69 to your computer and use it in GitHub Desktop.
Angular Simple Todo App
<!DOCTYPE html>
<html ng-app='todoApp'>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<title>TO DO List</title>
</head>
<body ng-controller='ToDoCtrl'>
<div class="page-header">
<h1>
{{todo.user}}'s To Do List
<span class='label label-default' ng-class='warningLevel()' ng-hide='incompleteCount() == 0'>{{ incompleteCount() }}</span>
</h1>
</div>
<div class="panel">
<div class="input-group">
<input class="form-control" ng-model='actionText' />
<span class="input-group-btn">
<button class="btn btn-default" ng-click='addNewItem(actionText)'>Add</button>
</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Done</th>
</tr>
</thead>
</tbody>
<tr ng-repeat="item in todo.items | checkedItems:showComplete | orderBy: 'action' ">
<td>{{item.action}}</td>
<td><input type='checkbox' ng-model="item.done" /></td>
</tr>
</tbody>
</table>
<div class='checkbox-inline'>
<label><input type='checkbox' ng-model='showComplete'>Show Complete</label>
</div>
</div>
<script id="jsbin-javascript">
var model = {
user: "Adam",
items: [{ action: "Buy Flowers", done: false},
{action: "Get Shoe", done: false},
{action: "Collect Ticketsl", done: true},
{action: "Call Joe", done: false}]
};
var todoApp = angular.module('todoApp', []);
todoApp.controller('ToDoCtrl', function($scope){
$scope.todo = model;
$scope.incompleteCount = function() {
var count = 0;
angular.forEach($scope.todo.items, function(item) {
if(!item.done) { count++; }
});
return count;
};
$scope.warningLevel = function() {
return $scope.incompleteCount() < 3 ? "label-success" : "label-warning";
};
$scope.addNewItem = function(actionText) {
$scope.todo.items.push({action: actionText, done: false});
$scope.actionText = '';
};
});
todoApp.filter('checkedItems', function(){
return function(items, showComplete){
var resultArr = [];
angular.forEach(items, function(item){
if (item.done == false || showComplete == true) {
resultArr.push(item);
}
});
return resultArr;
};
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html ng-app='todoApp'>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"><\/script>
<script src="//code.jquery.com/jquery.min.js"><\/script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"><\/script>
<title>TO DO List</title>
</head>
<body ng-controller='ToDoCtrl'>
<div class="page-header">
<h1>
{{todo.user}}'s To Do List
<span class='label label-default' ng-class='warningLevel()' ng-hide='incompleteCount() == 0'>{{ incompleteCount() }}</span>
</h1>
</div>
<div class="panel">
<div class="input-group">
<input class="form-control" ng-model='actionText' />
<span class="input-group-btn">
<button class="btn btn-default" ng-click='addNewItem(actionText)'>Add</button>
</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Done</th>
</tr>
</thead>
</tbody>
<tr ng-repeat="item in todo.items | checkedItems:showComplete | orderBy: 'action' ">
<td>{{item.action}}</td>
<td><input type='checkbox' ng-model="item.done" /></td>
</tr>
</tbody>
</table>
<div class='checkbox-inline'>
<label><input type='checkbox' ng-model='showComplete'>Show Complete</label>
</div>
</div>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">var model = {
user: "Adam",
items: [{ action: "Buy Flowers", done: false},
{action: "Get Shoe", done: false},
{action: "Collect Ticketsl", done: true},
{action: "Call Joe", done: false}]
};
var todoApp = angular.module('todoApp', []);
todoApp.controller('ToDoCtrl', function($scope){
$scope.todo = model;
$scope.incompleteCount = function() {
var count = 0;
angular.forEach($scope.todo.items, function(item) {
if(!item.done) { count++; }
});
return count;
};
$scope.warningLevel = function() {
return $scope.incompleteCount() < 3 ? "label-success" : "label-warning";
};
$scope.addNewItem = function(actionText) {
$scope.todo.items.push({action: actionText, done: false});
$scope.actionText = '';
};
});
todoApp.filter('checkedItems', function(){
return function(items, showComplete){
var resultArr = [];
angular.forEach(items, function(item){
if (item.done == false || showComplete == true) {
resultArr.push(item);
}
});
return resultArr;
};
});</script></body>
</html>
var model = {
user: "Adam",
items: [{ action: "Buy Flowers", done: false},
{action: "Get Shoe", done: false},
{action: "Collect Ticketsl", done: true},
{action: "Call Joe", done: false}]
};
var todoApp = angular.module('todoApp', []);
todoApp.controller('ToDoCtrl', function($scope){
$scope.todo = model;
$scope.incompleteCount = function() {
var count = 0;
angular.forEach($scope.todo.items, function(item) {
if(!item.done) { count++; }
});
return count;
};
$scope.warningLevel = function() {
return $scope.incompleteCount() < 3 ? "label-success" : "label-warning";
};
$scope.addNewItem = function(actionText) {
$scope.todo.items.push({action: actionText, done: false});
$scope.actionText = '';
};
});
todoApp.filter('checkedItems', function(){
return function(items, showComplete){
var resultArr = [];
angular.forEach(items, function(item){
if (item.done == false || showComplete == true) {
resultArr.push(item);
}
});
return resultArr;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment