formGroup expects a FormGroup instance
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 theFormGroup
isloginForm
therefore it should be<form [formGroup]="loginForm">
[formControlName]="dob"
which passes the value of the propertydob
which doesn't exist. What you need is to pass the stringdob
like[formControlName]="'dob'"
or simplerformControlName="dob"
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.
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]});