1
I have a checkbox that when clicked makes a push in an array of name perm_telas, but when I select again a check already selected it is not removing correctly the value of the array.
I tried something like:
@ViewChildren('myItem') item; //Aqui é meu check
perm_telas = []; //Aqui é meu array
OnCheckboxSelect(id, event) { //Caso ocorra um check na tela, adiciona para o array perm_telas o id daquela tela.
if (event.target.checked === true) {
this.perm_telas.push(id);
console.log(this.perm_telas);
}
if (event.target.checked === false) {//Caso clique em um já checado, retira aquele id do.
this.perm_telas = this.perm_telas.filter((item) => id !== id);
}
}
The insertion is taking place correctly, I believe there is something wrong in my logic of removing from the array.
The condition enters the second
if
?– Diego Souza
Yes, the problem is in implementing the remove
– veroneseComS
Pedro, this only works when the array is of objects. This code worked when my array was composed of ({id: id}) but I had to switch only to a numeric array, so this function no longer works for me
– veroneseComS
whereas the
item
is a numerical value, andid
also...this.perm_telas.filter((item) => item !== id)
– Pedro