0
As I click the button it should add what is written in the fields in the table, but it of the error:
Typeerror: $Scope.listClient.push is not a Function
My controller:
app.controller('MainController', ['$scope', function($scope) {
$scope.client = {};
$scope.listClient = {};
$scope.addClient = function(client){
$scope.listClient.push(client);
$scope.client = {};
}
$scope.deleteClient = function(indice){
$scope.listClient.splice(indice,1);
};
}]);
Index:
<!DOCTYPE html>
<html lang="pt-br" xml:lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Cadastro de Pessoas</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.6/angular.min.js" ></script>
<script src="js/app.js" ></script>
<script src="js/controllers/Client.js" ></script>
</head>
<body ng-app="myApp">
<div class="content" ng-controller="MainController">
<form ng-submit="addClient(client)">
<div class="dadosPessoais">
<label>Nome: </label>
<input type="text" ng-model="client.nome">
<label>Sobrenome: </label>
<input type="text" ng-model="client.sobrenome">
<label>Email: </label>
<input type="text" ng-model="client.email">
<label>Telefone: </label>
<input type="text" ng-model="client.telefone">
</div>
<input type="submit" value="Adicionar">
</form>
<table border="1">
<tr>
<th>Nome</th>
<th>Sobrenome</th>
<th>Telefone</th>
<th>E-mail</th>
<th>Excluir</th>
</tr>
<tr ng-repeat="client in listClient track by $index">
<td>{{client.nome}}</td>
<td>{{client.sobrenome}}</td>
<td>{{client.telefone}}</td>
<td>{{client.email}}</td>
<td ng-click="deleteClient($index)">X</td>
</tr>
</table>
</div>
</body>
</html>
Correctness, thank you.
– Rafaela Cordeiro