1

Not similar to https://stackoverflow.com/questions/52235952/cannot-read-property-of-undefined-reactive-forms

StackBlitz - https://stackblitz.com/edit/github-rbjwcd-wtrevw

Having issues with the above demo. I am trying to get the form builder to work with models as per the example. The issue is with the .group property.

contactForm: FormGroup;

  createFormGroupWithBuilderAndModel(formBuilder: FormBuilder) {
    return this.formBuilder.group({
      personalData: formBuilder.group(new PersonalData()),
      requestType: '',
      text: ''
    });
  }

I think the issue might be not initialising the form on the return like:

this.contactForm = this.formBuilder.group

Can anybody get this to run?

3
  • 2
    this.formBuilder is null Commented Oct 8, 2019 at 13:15
  • 2
    In constructor this.contactForm = this.createFormGroupWithBuilderAndModel(this.formBuilder); Commented Oct 8, 2019 at 13:17
  • Any reason you're passing formBuilder into createFormGroupWithBuilderAndModel rather than using this.formBuilder directly? (I assume it's me missing something) Commented Oct 8, 2019 at 13:22

1 Answer 1

4

Fixing your stackblitz...

 constructor(private formBuilder: FormBuilder) {
    this.contactForm = this.createFormGroupWithBuilderAndModel(formBuilder);
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Np, glad to help you. Maybe check stackoverflow.com/help/someone-answers ;-)

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.