4
I am learning angular.js and am having difficulties with the following code
var myapp = angular.module("myapp", [])
myapp.controller('controller', function reset($scope){
$scope.reset = function(){
$scope.nome = " ";
$scope.nota1 = " ";
$scope.nota2 = " ";
}
$scope.reset();
});
myapp.controller('controller', function enviar($scope){
$scope.enviar = function(){
nome = $scope.nome;
nota1 = $scope.nota1;
nota2 = $scope.nota2;
media = $scope.media;
situacao = $scope.situacao;
media = (nota1 + nota2)/2;
if (media >= 10){
situacao = "Aprovado";
} else if (media > 0 && media < 8 ){
situacao = "Reprovado";
} else {
situacao = "Em exame";
}
var $scope.student = {
nome, nota1, nota2, media, situacao
};
}
$scope.enviar();
});
Whenever I put the data in the form it does not update the table
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script type="text/javascript" src="cadastro.js"></script>
<title>Cadastro de Notas</title>
</head>
<body ng-app= "myapp" ng-controller= "controller">
<form action="index.html" method="GET">
<p>
<label for="studentname">Nome do estudante:</label>
<input type="text" id="nome" ng-model="student.name"/><br />
<label for="nota1">Primeira nota</label>
<input type="number" id="nota1" ng-model="student.nota1"/><br />
<label for="nota2">Segunda nota</label>
<input type="number" id="nota2" ng-model="student.nota2"/><br />
<button ng-click="enviar()">Enviar</button>
<button ng-click="reset()">Apagar</button>
</p>
</form>
<table border="2">
<tr>
<th>Nome</th>
<th>Nota 1</th>
<th>Nota 2</th>
<th>Media</th>
<th>Situacao</th>
</tr>
<tr ng-bind>
<th>{{nome}}</th>
<th>{{nota1}}</th>
<th>{{nota2}}</th>
<th>{{media}}</th>
<th>{{situacao}}</th>
</tr>
</table>
</body>
</html>
Please help me thanks
Thank you very much.
– John Muconto