jeudi 28 février 2019

Angular form control array of checkboxes

I have an array of objects that I would like to use as a form control as a list of checkboxes. If a checkbox is checked, it adds the checkbox value to the form control (which is a list and starts out empty). This is what I have so far:

userAddForm = new FormGroup({
  firstName: new FormControl('', [Validators.required,
  Validators.minLength(4)]),
  lastName: new FormControl('', [Validators.required,
  Validators.minLength(4)]),
  email: new FormControl('', [Validators.required,
  Validators.email]),
  username: new FormControl('', [Validators.required,
  Validators.minLength(4)]),
  password: new FormControl('', [Validators.required,
  Validators.minLength(5)]),
});

When the component is initialized, I instantiate the array and build it from a data source, and then I am thinking I have to do this:

this.userAddForm.addControl(this.locations);

But then what would I do in my template to make this work?




Aucun commentaire:

Enregistrer un commentaire