Created
December 4, 2014 13:06
-
-
Save celsofabri/03555e664cdf72feb834 to your computer and use it in GitHub Desktop.
Add tasks with Angular JS / Adicionando tarefas com Angular JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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