Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DinisCruz/a4483071f5095947706d to your computer and use it in GitHub Desktop.
Save DinisCruz/a4483071f5095947706d to your computer and use it in GitHub Desktop.
function TodoCtrl( $scope )
{
$scope.todos =
[
{ text: 'learn angular', done:true },
{ text: 'build an angular app', done:false },
{ text: 'A NEW Angular TO DO', done:true }
];
$scope.addTodo = function()
{
$scope.todos.push( { text: $scope.todoText, done:false} );
$scope.todoText = 'Default Text after a new Todo';
}
$scope.remaining = function()
{
var count = 0;
angular.forEach( $scope.todos, function( todo )
{
count += todo.done ? 0 : 1;
}
);
}
}
/* vim: set tabstop=2 shiftwidth=2 expandtab: */
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.css" />
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<h2> Todo </h2>
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span>
[ <a href="" ng-click="archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done" />
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="addTodo()">
<input type="text" ng-model="todoText" size="30" placeholder="add new todo here" />
<input class="btn-primary" type="submit" value="add" />
<p>
New Todo text: <b>{{todoText}}</b>
</p>
</form>
</div>
</body>
</html>
<!-- vim: set tabstop=2 shiftwidth=2 expandtab: -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment