How to correctly import FormGroup into NgModule in Angular 2

I am trying to import FromGroup , FormBuilder and FormControl into my CustomModule :

 import { FormsModule, FormGroup } from '@angular/forms'; @NgModule({ imports: [ FormsModule, FormGroup ] }) 

But this causes an error:

EXCEPTION: Not available (in promise): Error: Unexpected value of 'FormGroup' imported by module "CustomModule"

If I import only FormsModule , it works fine.

Any ideas?

+6
source share
1 answer

You cannot add FormGroup to import a module, just import it into the component in which you want to use FormGroup . You can add MODULES to the imports module. In addition, if you want to use the FormGroup directive, you will need to import the ReactiveFormsModule into your module:

 @NgModule({ imports: [ FormsModule, ReactiveFormsModule ] }) 
+14
source

Source: https://habr.com/ru/post/1011716/


All Articles