Skip to content

Instantly share code, notes, and snippets.

@celsofabri
Created December 4, 2014 13:06
Show Gist options
  • Save celsofabri/03555e664cdf72feb834 to your computer and use it in GitHub Desktop.
Save celsofabri/03555e664cdf72feb834 to your computer and use it in GitHub Desktop.
Add tasks with Angular JS / Adicionando tarefas com Angular JS
<html ng-app="NgApp">
<head>
<title>Add tasks with Angular JS / Adicionando tarefas com Angular JS</title>
</head>
<body>
<div ng-controller="TasksController">
<input type="text" name="tarefa" ng:model="nomeTarefa" ng:required>
<button ng:click="addTask()">Adicionar</button>
<ul>
<li ng:repeat="tarefa in tarefas track by $index">{{ tarefa }} <button ng:click="removeTask($index)">-</button></li>
</ul>
</div>
<script type="text/javascript">
/**
* Angular
*/
var app = angular.module('NgApp', ['ngMessages']);
app.controller('TasksController', ['$scope', function ($scope) {
$scope.tarefas = [];
$scope.addTask = function () {
$scope.tarefas.push($scope.nomeTarefa);
$scope.nomeTarefa = '';
};
$scope.removeTask = function (i) {
$scope.tarefas.splice(i, 1);
};
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment