Skip to content

Instantly share code, notes, and snippets.

@gabrielfeitosa
Last active August 29, 2015 14:27
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 gabrielfeitosa/1d71387ad0ebecd5c78d to your computer and use it in GitHub Desktop.
Save gabrielfeitosa/1d71387ad0ebecd5c78d to your computer and use it in GitHub Desktop.
Iniciando com Controller no AngularJS - Adicionando comportamento ao $scope
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>Exemplo 2 - Blog do Gabriel Feitosa</title>
</head>
<body>
<h1>Entendendo os Controladores</h1>
<div ng-controller="MeuController">
<form>
<input type="text" ng-model="item" placeholder="Informe um item" />
<button ng-click="addItem()">Adicionar</button>
</form>
<br/>
<h1> Itens</h1>
<ul>
<li ng-repeat="i in itens">{{i}}</li>
</ul>
</div>
<footer>
<hr/>
<a href="http://www.gabrielfeitosa.com"> Blog do Gabriel Feitosa</a>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script>
var app = angular.module('app', []);
app.controller('MeuController', ['$scope', function($scope) {
$scope.item = '';
$scope.itens = [];
$scope.addItem = function() {
$scope.itens.push($scope.item);
$scope.item = '';
}
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment