Skip to content

Instantly share code, notes, and snippets.

@renatocantarino
Created June 1, 2014 21:59
Show Gist options
  • Save renatocantarino/b42d79af450836b98858 to your computer and use it in GitHub Desktop.
Save renatocantarino/b42d79af450836b98858 to your computer and use it in GitHub Desktop.
Module.
<html ng-app='AngularIntro'>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body ng-controller='SimpleController'>
<input type='text' ng-model='name'>
<input type='button' value='Adicionar' ng-click='addName()'>
<table>
<tr ng-repeat="pessoa in Vizinhos">
<td>{{pessoa}}</td>
</tr>
</table>
<script>
//Inicialização do módulo
var module = angular.module('AngularIntro', []);
//Adição do Controller ao módulo
module.controller('SimpleController', function($scope){
$scope.Vizinhos = ['Jose', 'Mr M', 'Sbrubles', 'Maria'];
$scope.addName = function(){
var name = $scope.name;
if($scope.Vizinhos.indexOf(name) == -1)
$scope.Vizinhos.push(name);
$scope.name = '';
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment