ngFor with checkbox is selecting all values

Asked

Viewed 90 times

-1

I have the following checkbox with a repeating structure:

      <div *ngFor="let tela of telas" class="custom-control custom-checkbox check">
        <input type="checkbox" id="{{tela.nome_tela}}" [(ngModel)]="operador.permissao_telas" name="{{tela.id}}" class="custom-control-input" checked>
        <label class="custom-control-label" for="{{tela.nome_tela}}">{{tela.nome_tela}}</label>
      </div>

This is my model:

export class Operador{
    id: number;
    nome: string;
    permissao_telas: number[];
}

In my component I do:

 operador:Operador = new Operador();

The problem is that when I click on some check, all other check are selected too.

I tried it with index and it didn’t work either.

  • Place inside the div of the ngFor one <p>{{tela | json}}</p> and check that the data appears as the eperado

1 answer

0

Remove checked at the end of your html input

Browser other questions tagged

You are not signed in. Login or sign up in order to post.