Last active
August 29, 2015 14:27
-
-
Save gabrielfeitosa/1d71387ad0ebecd5c78d to your computer and use it in GitHub Desktop.
Iniciando com Controller no AngularJS - Adicionando comportamento ao $scope
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
<!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