I have a strange problem with checkboxes using angular2 (beta 17).
I'm trying to set same checkboxes as elements has the array and bind the change or click event.
For example I have an array:
myObjects=[
{value:true},
{value:true},
{value:false},
{value:true}
];
And I'm using the ngFor to create all the checkboxes:
<div *ngFor="let myObject of myObjects; let i = index" >
<input
type="checkbox"
[checked]="myObject.value"
(change)="updateCheckedOptions(i, $event)"
/>
</div>
And finally I have a function in my component:
@Input() myObjects;
updateCheckedOptions(index,event){
this.myObjects[index].value=event.target.checked;
}
But the problem is that the checkbox don't change, I mean that when I click the checkbox, if the initial state is checked, always remain checked and vice versa.
I have tried using (click), (change), [(ngModel)] but it does not work any.
Thanks!