Skip to content

Instantly share code, notes, and snippets.

@porcelli
Created June 14, 2015 12:39
Show Gist options
  • Save porcelli/d49ca4bac7ce84f85fab to your computer and use it in GitHub Desktop.
Save porcelli/d49ca4bac7ce84f85fab to your computer and use it in GitHub Desktop.
function TodoCtrl($scope) {
$scope.placeText = "MiscellaneousFeatures";
$scope.todos = [
{text: 'learn angular', done: true},
{text: 'build an angular app', done: false}
];
$scope.addTodo = function () {
$scope.todos.push({text: $scope.todoText, done: false});
$scope.todoText = '';
};
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.archive = function () {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function (todo) {
if (!todo.done) {
$scope.todos.push(todo);
}
});
};
$scope["goto"] = function () {
$goToPlace($scope.placeText);
};
}
<div class="container-fluid" ng-controller="TodoCtrl">
<div class="row">
<div class="col-md-12">
<p class="pull-right" style="margin-top: 10px;">{{remaining()}} of {{todos.length}} remaining [
<a href="" ng-click="archive()">archive</a> ]
</p>
<h4>Todos</h4>
<ul class="list-group">
<li class="list-group-item" ng-repeat="todo in todos">
<span class="done-{{todo.done}}">{{todo.text}}</span>
<input class="pull-right" type="checkbox" ng-model="todo.done">
</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-6">
<form class="form-inline" ng-submit="goto()">
<div class="form-group">
<input type="text" ng-model="placeText" size="30" class="form-control" placeholder="place to go">
<input class="btn btn-primary" type="submit" value="GoTo">
</div>
</form>
</div>
<div class="col-md-6">
<form class="form-inline pull-right" ng-submit="addTodo()">
<div class="form-group">
<input type="text" ng-model="todoText" size="30" class="form-control" placeholder="add new todo here">
<input class="btn btn-primary" type="submit" value="Add">
</div>
</form>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment