I m using a checkbox in Angular to select more than one element and I'm trying to get the value of that checkbox for submitting.
Instead I'm getting the value those values as an array of true
-s.
That's what I've tried:
export class CreateSessionComponent implements OnInit {
form : FormGroup ;
constructor(private formBuilder: FormBuilder) {}
ngOnInit() {
this.form = this.formBuilder.group({
userdata : new FormArray([
new FormControl('', Validators.required)
])
})
}
}
userdata
is a dynamic array populated from a database.
<div formArrayName="useremail; let k = index">
<div *ngFor="let data of userdata">
<div>
<input type="checkbox" name="useremail" formControlName ="{{k}}" [value]="data.email">{{data.email}}
</div>
</div>
</div>
Question&Answers:os