Set and update validation on form array in reactive forms


In angular 4 i am creating a form that has a form array like so{
  name: ['', [Validators.required, Validators.minLength(3)]],
  selectType: ['', [Validators.required]],
  items: this.formBuilder.array([this.buildItems()])

buildItems() {
     name: ['', [Validators.required]] 

This builds the form and i can i add remove etc from this form and items in the form.
What i am now trying to achieve is that when the selectType is equal to custom ( which is set as a radio button value on the form ) then i need to change the validation of the items name and clear its validation requirement.

I have done an set and update on a another form like so

  changeValidation() {

Which works fine, however i am not sure how to update the validations on the form array. I have tried


I dont get any errors but it also doesn’t work. Which kind of makes sense because i am not targeting a specific FormControl however how do i specify a specific FormControl when the FormControls are an array?


how do i specify a specific FormControl when the FormControls are an

You have to use at method described here to get a single control:;

If you want to clear validators for the name control, do like that:;

If you want to remove validators for every control, it seems that form array doesn’t provide such API. You have to iterate over the form array controls and remove validators for each control:

this.items.controls.forEach(c => c.clearValidators());

Answered By – Max Koretskyi

Answer Checked By – Robin (AngularFixing Admin)

Leave a Reply

Your email address will not be published.