Skip to content

Instantly share code, notes, and snippets.

@navio
Created September 8, 2013 04:27
Show Gist options
  • Save navio/6481832 to your computer and use it in GitHub Desktop.
Save navio/6481832 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/sugar/1.3.9/sugar.min.js"></script>
<meta charset=utf-8 />
<title>Todo List - Using Angular</title>
</head>
<body>
<fieldset>
<div ng-controller="myTasks">
<input ng-model="task">
<input class="btn-add" type="button"
ng-click="addToDo()" class="btn" value="Add">
<li ng-repeat="task in tasks | orderBy:'name' ">
{{ task.name }}
<a href="#">
<span ng-click="removeToDo(task)" >X</span>
</a>
</li>
</div>
</fieldset>
</body>
</html>
function myTasks($scope){
$scope.tasks = [
{"id": 1,"name": "Nexus S"},
{"id": 2,"name": "Motorola XOOM™ with Wi-Fi"},
{"id": 3,"name": "MOTOROLA XOOM™"}
];
$scope.addToDo = function(){
var newID = $scope.tasks.lenght;
$scope.tasks.push({id:newID,name:$scope.task});
$scope.task = "";
};
$scope.removeToDo = function(list){
for (var i = 0, len = $scope.tasks.length; i < len; i++) {
if(list.id == $scope.tasks[i].id ){
$scope.tasks.splice(i, 1);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment