1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
function todoCtrl($scope, filterFilter,$http){
$scope.todos = [];
$scope.placeholder = 'Chargement...';
$http.get('php/lister.php').success(function(data){
$scope.todos = data;
$scope.placeholder = 'Ajouter une nouvelle tâche';
}).error(function(){
$scope.placeholder = 'Erreur de chargement de données !';
});
$scope.$watch('todos',function(){
$scope.remaining = filterFilter($scope.todos, {completed:false}).length;
$scope.allchecked = !$scope.remaining;
},true)
$scope.removeTodo = function(index){
$scope.todos.splice(index,1);
}
$scope.addTodo = function(){
$http.post('php/add.php',{'tache':$scope.newtodo},{'Content-Type':'application/x-www-form-urlencoded'}).success(function(){
alert("Ajout bien réaliser");
}).error(function(){
alert('Problème d\'insertion des la tâche dans la base de données');
});
$scope.placeholder = '';
}
$scope.checkAllTodo = function(allchecked){
$scope.todos.forEach(function(todo){
todo.completed = allchecked;
})
}
} |
Partager