0

I am trying to create a method to delete rows from my dynamic form and I am having trouble targeting the array.

so the form group is this:

this.piForm = this.fb.group({
    milestoneSaveModel: this.fb.group({
        milestonesToCreate: this.fb.array([this.mileStoneCreate()]),
    }),
});

and then my delete method is this so far:

deleteRow(index: number) {
    const control = <FormArray>this.piForm.controls['milestoneSaveModel'].controls['milestonesToCreate'];
    control.removeAt(index);
}

my linter tells me Property 'controls' does not exist on type 'AbstractControl'.

however when I trigger this in the browser it actually works. So how do i fix the linting error?

3
  • 1
    Try with this.piForm.get('milestoneSaveModel').get('milestonesToCreate') and tell me how it goes. Commented Mar 22, 2018 at 13:56
  • yep that worked like a charm! Commented Mar 22, 2018 at 13:58
  • I made an answer, feel free to mark your issue as resolved once you can Commented Mar 22, 2018 at 14:06

2 Answers 2

2

use this syntax instead :

this.piForm.get('milestoneSaveModel').get('milestonesToCreate')
Sign up to request clarification or add additional context in comments.

Comments

0

You need to convert type of control to FormArray.

form.get('milestoneSaveModel').get('milestonesToCreate') as FormArray;

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.