mercredi 3 mai 2017

How to solve checkbox modifying other checkboxes state (not the model)?

I have a for that goes over elements in a array of Boolean variables and uses each Boolean as a model for a checkbox. The models array looks like this:

  models = [true,false,true,true,false,false,true];

The template looks like this:

<h1>Hello </h1><br>
<div *ngFor="let mod of models; let i=index">
    <input [(ngModel)]="models[i]" type="checkbox">
</div>
<pre></pre>

When I click a checkbox, a random element changes it's state too.

Not sure if this is a bug or I'm just not understanding something.

How do I make this checkboxes behave appropriately?

http://ift.tt/2pxrG3q <-- Complete example showing this behavior

Thanks in advanced for any help!




Aucun commentaire:

Enregistrer un commentaire