В .ts файле создать массив для ролей
Roles = [
{ id: true, description: 'W9' },
{ id: true', description: 'F9' },
{ id: true, description: 'other' },
];
this.customerForm = this.fb.group({
roles: this.fb.array([]),
});
функция для проверки и снятия отметки
updateChkbxArray(chk, isChecked, key): void {
const chkArray = <FormArray>this.customerForm.get(key);
if (isChecked) {
// sometimes inserts values already included creating double records for the same values -hence the defence
if (chkArray.controls.findIndex(x => x.value === chk.id) === -1)
chkArray.push(new FormControl(chk.id));
} else {
const idx = chkArray.controls.findIndex(x => x.value === chk.id);
chkArray.removeAt(idx);
}
}
В настоящее время я показываю флажок в поле угловой материал. Вы можете иметь свой собственный флажок.
<mat-checkbox *ngFor="let role of Roles" formArrayName="roles"
(change)="updateChkbxArray(role, $event.checked, 'roles')"
[value]="role.id">{{role.description}}
</mat-checkbox>