Skip to content

Instantly share code, notes, and snippets.

@ozaydinb
Last active December 26, 2015 20:59
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 ozaydinb/7213361 to your computer and use it in GitHub Desktop.
Save ozaydinb/7213361 to your computer and use it in GitHub Desktop.
Angular.js Todo Sample
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="todoController.js"></script>
<script src="todo.js"></script>
<style type="text/css">
.todoCompleted {
text-decoration: line-through;
}
</style>
</head>
<body>
<div ng-controller="todoController">
<table>
<tr>
<td colspan="2">Ara:<input type="text" ng-model="searchText" /></td>
</tr>
<tr>
<td><input type="text" ng-model="todoName"> </input></td>
<td><button ng-click="addTodo(todoName)">Ekle</button></td>
</tr>
</table>
<ul>
<li ng-repeat="todo in todoList | filter:searchText">
<input type="checkbox" ng-model="todo.isCompleted">
<span ng-class="{todoCompleted:todo.isCompleted}">{{todo.name}}</span>
<button ng-click="deleteTodo($index)">Sil</button>
</li>
</ul>
</div>
</body>
</html>
/**
* Created by Baris.Ozaydin on 29.10.2013.
*/
var todo= function(name) {
return {
name:name,
isCompleted:false
}
};
/**
* Created by Baris.Ozaydin on 29.10.2013.
*/
'use strict';
function todoController($scope) {
$scope.todoList =[];
$scope.deleteTodo = function(index) {
$scope.todoList.splice(index,1);
};
$scope.addTodo = function() {
var id = $scope.todoList.length;
$scope.todoList.push(new todo($scope.todoName,id));
$scope.todoName='';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment