0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try disabling the form control when you are creating it.

For example :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.