formGroup expects a FormGroup instance

前端 未结 4 1701
无人及你
无人及你 2020-12-03 06:22

I have an Angular 2 RC4 basic form example on Plunkr that appears to throw the following error (In Chrome DEV console)

Here\'s the plunkr

https://plnkr.co/ed

相关标签:
4条回答
  • 2020-12-03 06:50

    There are a few issues in your code

    • <div [formGroup]="form"> outside of a <form> tag
    • <form [formGroup]="form"> but the name of the property containing the FormGroup is loginForm therefore it should be <form [formGroup]="loginForm">
    • [formControlName]="dob" which passes the value of the property dob which doesn't exist. What you need is to pass the string dob like [formControlName]="'dob'" or simpler formControlName="dob"

    Plunker example

    0 讨论(0)
  • 2020-12-03 06:59

    I was facing this issue and fixed by putting a check in form attribute. This issue can happen when the FormGroup is not initialized.

    <form [formGroup]="loginForm" *ngIf="loginForm">
    OR
    <form [formGroup]="loginForm" *ngIf="this.loginForm">
    

    This will not render the form until it is initialized.

    0 讨论(0)
  • 2020-12-03 07:01

    I had this error when I had specified fromGroupName instead of formArrayName.

    Make sure you correctly specify if it is a form array or form group.

    <div formGroupName="formInfo"/>

    <div formArrayName="formInfo"/>

    0 讨论(0)
  • 2020-12-03 07:16

    I was using reactive forms and ran into similar problems. What helped me was to make sure that I set up a corresponding FormGroup in the class. Something like this:

    myFormGroup: FormGroup = this.builder.group({
        dob: ['', Validators.required]
    });
    
    0 讨论(0)
提交回复
热议问题