Skip to content

Instantly share code, notes, and snippets.

@mmarchois
Created January 29, 2013 12:47
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 mmarchois/4663978 to your computer and use it in GitHub Desktop.
Save mmarchois/4663978 to your computer and use it in GitHub Desktop.
todolist_angular
function todoController($scope) {
$scope.todos = [
{
name : 'Ma premiere tâche'
},
{
name : 'Ma seconde tâche'
}
];
$scope.$watch('todos', function(){
$scope.remaining = $scope.todos.length;
}, true);
$scope.removeTodo = function (index) {
$scope.todos.splice(index, 1);
}
$scope.addTodo = function() {
$scope.todos.push({
name : $scope.newtodo
});
$scope.newtodo = '';
}
}
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="controller.js"></script>
</head>
<body ng-app>
<section ng-controller="todoController">
<form action="#" ng-submit="addTodo()">
<input type="text" name="todoName" ng-model="newtodo"/>
</form>
<ul id="todo-list">
<li ng-repeat="todo in todos">
<input type="checkbox" class="toggle" />
<label>{{ todo.name }}</label>
<button ng-click="removeTodo($index)"></button>
</li>
</ul>
<footer>{{ remaining }}</footer>
</section>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment