0

I'm using Angular 6 and have written API in Django.

I have a Profile model serialized under User model.

Using Postman I'm able to save records to Profile like

# JSON
{
    'name': 'John',
    'profile': {
       'about': 'About me string'
    }
}

# or form field
name = 'John'
profile.about = 'About me string'

Now, In Angular application, I am trying to send data in the same format described above to the endpoint. For that, the formGroup is like

this.aboutForm = this.fb.group({
  profile: this.fb.group({
    about: new FormControl('', [
        Validators.required
    ])
  })
});

And when the HTML form be like

<form [formGroup]="aboutForm" (submit)="submit()" #form="ngForm">
    <textarea formControlName="profile.about"></textarea>
</form>

But this is giving error as

error service Error: "Cannot find control with name: 'profile.about'"

1 Answer 1

2

You should use formGroupName instead of formControlName for nested controls.

Enclose the textarea inside div with formGroupName=profile and then use the formControlName=about for your texarea

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

1 Comment

what should be the value of formGroupName?

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.