1
I have a checkbox that is iterated on an ngfor:
<div *ngFor="let tela of telas; let i = index; trackBy: getIndex" class="custom-control custom-checkbox check">
<input type="checkbox" [(ngModel)]=selectedIds[i] (click)="OnCheckboxSelect(tela.id, $event)" #myItem value="{{tela.id}}" id="{{tela.nome_tela}}" name="{{tela.nome_tela}}" class="custom-control-input">
<label class="custom-control-label" for="{{tela.nome_tela}}">{{tela.nome_tela}}</label>
</div>
There is a moment when I get the array of selectedIds again to make changes, but I get the array in the following format:
[1.3.5] These are the screen ids that a user can access, but my ngModel would need to receive: [0:true, 2:true, 4:true] to bind.
I’m trying to make a repeating structure to achieve the desired result. I tried something like:
this.selectedIds = [];
for(let i=0;i<this.operador.tabela_perm.length;i++){
this.selectedIds[this.operador.tabela_perm - 1] = true;
}
But my logic is still wrong. Could someone help me?
The
this.operador.tabela_perm
is the array[1,3,5]
?– Renata
@Renata yes, I need to transform it into the format in which ngmodel performs the bind [key: true]
– veroneseComS