0
BuildCustomFields(formControl, formControlValue): FormGroup {
    return this.fb.group({      
      formControl: new FormControl(formControlValue),
    })
  }

I need to add formControl Value from parameter which I pass in BuildCustomFields() method. How can pass the value of formControl dynamically?

It always takes this text "formControl" as key instead of using value which I am passing to it.

0

1 Answer 1

1

If you want formControl to be your dynamic key, you need to pass reference it within [] otherwise you get the value of it

BuildCustomFields(formControl, formControlValue): FormGroup {
debugger
return this.fb.group({
  
 [formControl]: new FormControl(formControlValue),
})
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Salmin Skenderovic Its working but when I give dynamic key it says "Component.html:715 ERROR Error: Cannot find control with path: 'customFieldArray -> 0 -> Matter Value'" When I give static value it works fine. Can you please tell me why it is throwing this error?
I have updated my question can you please have a look at html code I am giving formControlName with interpolation when I give formControl in BuildCustomFields() with static way it works fine but in dynamic way its giving this error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.