In my Offer class, I have a property called "units" which is an array of objects.
export class Offer {
public propertyA: string;
public propertyB: string;
public units: Unit[];
}
export class Unit {
public code: string,
public name: string,
public checked: boolean
}
I am developing with Angular 2 and want to display these units as selectable checkboxes for the user. I am also utilizing angular material components.
The HTML implementation looks like this:
<div *ngFor="let unit of model.units; let i=index">
<mat-checkbox [(ngModel)]="model.units[i].checked"
id="units[{{i}}]" name="units[{{i}}]">
{{ unit.name }}
</mat-checkbox>
</div>
To load the units property, I use the following:
this.model.units.push(new Unit("code1","name1", false));
this.model.units.push(new Unit("code2","name2", false));
this.model.units.push(new Unit("code3","name3", false));
However, when I submit the form, the checked property does not retain the selected values. What could be causing this issue?