I am aware of both FormArray from reactive forms and the method of objects in an array or map as described in this question. Normally I would use the former, and if absolutely necessary the latter - but I would like to know if it is possible with just an array of boolean
values.
template
<div>
<h2>Hello {{name}}</h2>
</div>
<input type="checkbox" *ngFor="let item of items; let i = index;" [(ngModel)]="items[i]"/>
component
@Component({
selector: 'my-app',
template: `...`,
})
export class App {
name:string;
items = [false, false, true];
constructor() {
this.name = `Angular! v${VERSION.full}`
}
}
With the files as above, clicking the first checkbox will change the value of other checkboxes. Is there a mistake I have made, or is this not possible in Angular?
Gif showing the incorrect behaviour: