Created
January 29, 2013 12:47
-
-
Save mmarchois/4663978 to your computer and use it in GitHub Desktop.
todolist_angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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