JSFiddle - React, Tailwind, and code Playground
by kfuchs
HTML
<script src="https://rawgit.com/kfuchs/angular-focus-on/master/src/focus-on.js"></script>
<body ng-app="todoApp" ng-controller="ToDoCtrl">
<div class="page-header">
<h1>
{{todo.user}}'s To Do List
<span class="label label-default">
</span>
</h1>
</div>
<div class="panel">
<div class="input-group">
<input id="getFocus" ng-model="actionText" class="form-control" focus-on event="todoAdded" />
<span class="input-group-btn">
<button ng-click="addNewItem(actionText)" class="btn btn-default">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:'done'">
<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>
JavaScript
var model = {
user: "Adam"
}
var todoApp = angular.module('todoApp',['kf.focusOn']);
//get data
todoApp.run(function($http){
$http.get('todo.json').success(function(data){
model.items = data;
});
});
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;
}
})
todoApp.controller('ToDoCtrl',function($scope){
$scope.todo = model;
$scope.todo.items = [];
$scope.incompleteCount = function(){
var count =0;
angular.forEach($scope.todo.items,function(item){
if(!item.done){
count++;
}
});
return count;
}
$scope.addNewItem = function(actionText){
$scope.$broadcast('todoAdded');
$scope.todo.items.push({action: actionText, done: false});
$scope.actionText = "";
};
});