我要生成带有数组的复选框
component.ts
profiles: string[] = [
'Sales Admin',
'Finance Admin',
'Gateway Admin',
'Support Admin',
];
profileControls: any;
//creating formcontrols
constructor() {
this.profileControls = this.profiles.map(c => new FormControl(false));
this.createFormControls();
this.createForm();
}
createFormControls() {
this.userid = new FormControl('', Validators.email);
this.accsprofile = new FormArray(this.profileControls);
}
createForm() {
this.myform = new FormGroup({
userid: this.userid,
accsprofile: this.accsprofile
});
}
component.html
<div *ngFor="let profile of profileControls let i=index" >
<mat-checkbox class="example-margin" [formControlName]="profiles[i]">
{{profiles[i]}}
</mat-checkbox>
</div>
尽管我选中了所有复选框,但输出显示为false。我想获取已选中复选框的值