Home > Software design >  Data from the JSON is not displayed in the inputs of the FormArray
Data from the JSON is not displayed in the inputs of the FormArray

Time:10-11

I have a JSON and would like to output the data from this object to the FormArray. I am only getting Object object displayed in the output. What is the best way to solve this problem and what can I do better in building the code?

My StackBlitz: enter image description here

Reactive forms Angular docs

CodePudding user response:

FormBuilder control takes an object containing default value and disabled state or just the default value so update your generate form method like this:

private generateUserFormGroup(param) {
 return this.fb.group({
  gender: this.fb.control(param.gender),
  email: this.fb.control({ value: param.email, disabled: false }),
 });
}

And where your are calling this function you need to pass the currentUser

this.generateUserFormGroup(data[0].currentUser)

Check this

  • Related