I\'m new in angular 2 and i try to make a reactive form but i have some trouble. After many search in stack i found no solutions.
Here you can see my error
I had the same problem and I solved the problem in another way, without import ReactiveFormsModule. You may be but this block in
ngOnInt(){
userForm = new FormGroup({
name: new FormControl(),
email: new FormControl(),
adresse: new FormGroup({
rue: new FormControl(),
ville: new FormControl(),
cp: new FormControl(),
})
});
)
For those still struggling with the error, make sure that you also import ReactiveFormsModule in your component 's module.ts file
meaning that you will import your ReactiveFormsModule in your app.module.ts and also in your mycomponent.module.ts file
I think that this is an old error that you tried to fix by importing random things in your module and now the code does not compile anymore. while you don't pay attention to the shell output, the browser reload, and you still get the same error.
Your module should be :
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ContactComponent
]
})
export class ContactModule {}
Try to add ReactiveFormsModule in your component as well.
import { FormGroup, FormArray, FormBuilder,
Validators,ReactiveFormsModule } from '@angular/forms';
try with
<form formGroup="userForm">
instead of
<form [formGroup]="userForm">
I have solved it by importing FormModule in a shared.module and importing the shared.module in all other modules. My case is the FormModule is used in multiple modules.