Contrôleurs 3

by bestmomo

HTML

<div ng-app ng-controller="controleur">
        <form ng-submit="ajouter(nom, age)">
		Nom : <input type="text" name="nom" ng-model="nom">
		Age : <input type="number" name="age" ng-model="age">
		<button type="submit">Ajouter</button>
	</form>
	<table>
		<caption>Personnes</caption>
		<tr>
			<th>Nom</th>
			<th>Age</th>
		</tr>
		<tr ng-repeat="personne in personnes">
			<td>{{personne.nom}}</td>
			<td>{{personne.age}}</td>
		</tr>
	</table>
	<script>
		function controleur($scope) {
			$scope.personnes = new Array();
			$scope.ajouter = function(nom, age) {
				$scope.personnes.push({'nom': nom, 'age': age});
			};
		}
	</script>
</div>

CSS

table {
    width: 100%;
}
table, tr, td {
    border: 1px solid #DDDDDD;
    border-collapse: collapse;
}