Sivamohan Reddy
Sivamohan Reddy

Reputation: 574

Disable form control of form array : Angular2

I've created a FormArray with a List of formGroups.

Now, I am trying to disable the control of each formGroup by looping FormArray.

this.otcDocumentTrackerForm.controls.forEach(s => {
  s.controls["isNotApproved"].disabled();
  s.controls["CREDIT_OR_OPS_REMARKS"].disabled();
});

However, this is not working for me. Can anyone give me a solution for this?

Upvotes: 0

Views: 3521

Answers (2)

Ebin Manuval
Ebin Manuval

Reputation: 1255

You can disable form controls by iterating through form array

diableInputs() {
    this.myForm.controls.forEach((group: FormGroup) => {
        let isNotApproved = group.get('isNotApproved') as FormControl;
        isNotApproved.disable()
        let credit = group.get('CREDIT_OR_OPS_REMARKS') as FormControl;
        credit.disable()
    })
}

Check stackblitz for complete example.

Upvotes: 1

Sarthak Aggarwal
Sarthak Aggarwal

Reputation: 2312

Try disabling the form control when you are creating it.

For example :

isNotApproved: new FormControl({ value: false, disabled: true }, Validators.required)

Upvotes: 0

Related Questions