I have a question about the disabled. I have an array of pessoas
that I want to include in an array of empresa
. I use data-ng-repeat to display the pessoas
in a table, where buttons are added to each row to be added in the empresa
array. I've disabled the ability to add a person to the business through disabled
so that there is no duplicate registration.
var a = angular.module("2",[]);
a.controller("controller", function($scope){
$scope.pessoas= [{nome:"Rodrigo", data:"18/01/1991", id:"1"},
{nome: "Ana", data:"12/04/1959", id:"2"},
{nome: "Teresa", data:"19/07/1984", id:"3"}];
$scope.empresa=[];
$scope.adicionarContatos = function(pessoa){
$scope.empresa.push(angular.copy(pessoa));
};
$scope.removerContato = function(z){
$scope.empresa.pop(z);
};
});
<table>
<tr>
<th>Nome</th>
<th>Data</th>
</tr>
<tr data-ng-repeat="z in pessoas">
<td data-ng-bind="z.nome"></td>
<td data-ng-bind="z.data"></td>
<td> <button class="btn btn-sucess fa fa-shopping-cart" data-ng-click="adicionarContatos(z)" onclick="disabled=true"></button>
</td>
</tr>
</table>
However, as a consequence, I can no longer re-enable the same button by deleting an object from the empresa
array, which is also displayed in another table through ng-repeat.
<table>
<tr>
<th>Nome</th>
<th>Data</th>
</tr>
<tr data-ng-repeat="z in empresa">
<td data-ng-bind="z.nome"></td>
<td data-ng-bind="z.data"></td>
<td> <button class="btn btn-sucess fa fa-shopping-cart" data-ng-click="removerContato(z)" </button>
</td>
</tr>
</table>
What do I need to do so that by removing the person from empresa
, it automatically enables the person in pessoas
? I have tried to assign id to each button, but only the first one is set and document.getElementByID
does not work.