Conforme eu clicar no botão ele deveria adicionar o que esta escrito nos campos na tabela, mas ele da erro:
TypeError: $scope.listClient.push is not a function
Meu 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>