I want to get the all checkboxes items when user selects, now am getting the data 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.
this.settings_data = ["one", "two", "three", "four", "five"];
<div class="settings_head" fxFlex="50" *ngFor="let item of settings_data">
<mat-checkbox formControlName="settingsCheckboxvalues" (ngModelChange)="seleteditems($event,item)">{{item}}</mat-checkbox>
</div>
seleteditems(event, value) {
this.allitems.push(value);
}
I think you are overcomplicating things.
Modify your array so that each entry has a
name
and achecked
property, and bind the checkboxes to them with[(ngModel)]
ts
html
Demo
Using reactive forms would be easier :
The template :
Here is an edit of your stackblitz.