My solution - solved it for Angular 5 with Material View
The connection is through the
formArrayName="notification"
(change)="updateChkbxArray(n.id, $event.checked, 'notification')"
This way it can work for multiple checkboxes arrays in one form. Just set the name of the controls array to connect each time.
constructor(_x000D_
private fb: FormBuilder,_x000D_
private http: Http,_x000D_
private codeTableService: CodeTablesService) {_x000D_
_x000D_
this.codeTableService.getnotifications().subscribe(response => {_x000D_
this.notifications = response;_x000D_
})_x000D_
..._x000D_
}_x000D_
_x000D_
_x000D_
createForm() {_x000D_
this.form = this.fb.group({_x000D_
notification: this.fb.array([])..._x000D_
});_x000D_
}_x000D_
_x000D_
ngOnInit() {_x000D_
this.createForm();_x000D_
}_x000D_
_x000D_
updateChkbxArray(id, isChecked, key) {_x000D_
const chkArray = < FormArray > this.form.get(key);_x000D_
if (isChecked) {_x000D_
chkArray.push(new FormControl(id));_x000D_
} else {_x000D_
let idx = chkArray.controls.findIndex(x => x.value == id);_x000D_
chkArray.removeAt(idx);_x000D_
}_x000D_
}
_x000D_
<div class="col-md-12">_x000D_
<section class="checkbox-section text-center" *ngIf="notifications && notifications.length > 0">_x000D_
<label class="example-margin">Notifications to send:</label>_x000D_
<p *ngFor="let n of notifications; let i = index" formArrayName="notification">_x000D_
<mat-checkbox class="checkbox-margin" (change)="updateChkbxArray(n.id, $event.checked, 'notification')" value="n.id">{{n.description}}</mat-checkbox>_x000D_
</p>_x000D_
</section>_x000D_
</div>
_x000D_
At the end you are getting to save the form with array of original records id's to save/update.
Will be happy to have any remarks for improvement.