0
I’m having a question about the disabled. I have an array of pessoas
I want to include in an array of empresa
. I use data-ng-repeat to display pessoas
in a table, where buttons are added to each row so that they are added in the array empresa
. I disabled the functionality of adding a person to the company through disabled
so that there is no duplicate record.
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 rehabilitate the button even by deleting an object from the array empresa
, which is also displayed in another table via 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 I need to do to that, while 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 the document.getElementByID
doesn’t work.
You have to create in the People array a Boolean item so you can change the user from enabled to not enabled and vice versa! an idea.
– novic
But what function would I use with the boolean value of the people array to modify the disabled on the button inside ng-repeat? onclick(disable=z.disabled) is a javascript function and does not recognize z.
– Rodrigo Ferraz