Skip to content

Instantly share code, notes, and snippets.

@Atefnouri
Created August 2, 2017 20:19
Show Gist options
  • Save Atefnouri/4a9baebcb708e080f6a9b9f5a3e6ff51 to your computer and use it in GitHub Desktop.
Save Atefnouri/4a9baebcb708e080f6a9b9f5a3e6ff51 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="todo">
<head>
<meta charset="utf-8">
<style>
.done{
text-decoration: line-through;
color: #ccc;
}
</style>
<script src="bower_components/angular/angular.js"></script>
<title></title>
</head>
<body>
<div ng-controller="TodoController">
<form name="frm" ng-submit="addtodo()">
<input type="text" name="newtodo" ng-model="newtodo" required>
<button ng-disabled="frm.$invalid">GO</button>
</form>
<button ng-click="clearCompleted()">Clear Completed</button>
<ul>
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done">
<span ng-class="{'done':todo.done}" >{{todo.title}}</span>
</li>
</ul>
</div>
<script>
angular.module('todo', [])
.controller('TodoController', ['$scope', function($scope){
$scope.todos = [{'title':'Build ng app','done':false}];
$scope.addtodo = function(){
$scope.todos.push({'title':$scope.newtodo ,'done':false});
$scope.newtodo = '';
}
$scope.clearCompleted = function(){
$scope.todos = $scope.todos.filter(function(item){
return !item.done
})
};
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment