添加 angular 响应式表单后出现此错误 "Cannot import "import {FormGroup, FormControl} from '@angular/forms'"
Getting this error "Cannot import "import {FormGroup, FormControl} from '@angular/forms'" after adding angular Reactive form
我想在 Angular 中为一个简单的注册组件构建一个响应式表单。我在尝试着
从 '@angular/forms' 导入 {FormGroup, FormControl} 但出现此错误。虽然我在 app.module
中导入了 {FormsModule, ReactiveFormsModule}
错误:
**core.js:6272 ERROR Error: NodeInjector: NOT_FOUND [ControlContainer]
at getOrCreateInjectable (core.js:5906)
at Module.ɵɵdirectiveInject (core.js:21251)
at NodeInjectorFactory.NgControlStatusGroup_Factory [as factory] (forms.js:1073)
at getNodeInjectable (core.js:6037)
at instantiateAllDirectives (core.js:12965)
at createDirectivesInstances (core.js:12181)
at Module.ɵɵelementStart (core.js:21434)
at SignupComponent_Template (signup.component.html:1)
at executeTemplate (core.js:12141)
at renderView (core.js:11911)
defaultErrorLogger @ core.js:6272
handleError @ core.js:6325
(anonymous) @ core.js:43091
invoke @ zone-evergreen.js:364
run @ zone-evergreen.js:123
runOutsideAngular @ core.js:41772
(anonymous) @ core.js:43088
invoke @ zone-evergreen.js:364
onInvoke @ core.js:41938
invoke @ zone-evergreen.js:363
run @ zone-evergreen.js:123
(anonymous) @ zone-evergreen.js:857
invokeTask @ zone-evergreen.js:399
onInvokeTask @ core.js:41916
invokeTask @ zone-evergreen.js:398
runTask @ zone-evergreen.js:167
drainMicroTaskQueue @ zone-evergreen.js:569
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:552
scheduleTask @ zone-evergreen.js:388
scheduleTask @ zone-evergreen.js:210
scheduleMicroTask @ zone-evergreen.js:230
scheduleResolveOrReject @ zone-evergreen.js:847
then @ zone-evergreen.js:979
bootstrapModule @ core.js:42948
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:78
0 @ main.ts:12
__webpack_require__ @ bootstrap:78
checkDeferredModules @ bootstrap:44
webpackJsonpCallback @ bootstrap:31
(anonymous) @ main.js:1
main.ts:12 Error: NodeInjector: NOT_FOUND [ControlContainer]
at getOrCreateInjectable (core.js:5906)
at Module.ɵɵdirectiveInject (core.js:21251)
at NodeInjectorFactory.NgControlStatusGroup_Factory [as factory] (forms.js:1073)
at getNodeInjectable (core.js:6037)
at instantiateAllDirectives (core.js:12965)
at createDirectivesInstances (core.js:12181)
at Module.ɵɵelementStart (core.js:21434)
at SignupComponent_Template (signup.component.html:1)
at executeTemplate (core.js:12141)
at renderView (core.js:11911)**
如果您使用 ReactiveFormsModule 和没有 FormGroup 的 <form>
元素,即您需要在绑定后使用表单,如 [formGroup]="myForm".
我想在 Angular 中为一个简单的注册组件构建一个响应式表单。我在尝试着 从 '@angular/forms' 导入 {FormGroup, FormControl} 但出现此错误。虽然我在 app.module
中导入了 {FormsModule, ReactiveFormsModule}错误:
**core.js:6272 ERROR Error: NodeInjector: NOT_FOUND [ControlContainer]
at getOrCreateInjectable (core.js:5906)
at Module.ɵɵdirectiveInject (core.js:21251)
at NodeInjectorFactory.NgControlStatusGroup_Factory [as factory] (forms.js:1073)
at getNodeInjectable (core.js:6037)
at instantiateAllDirectives (core.js:12965)
at createDirectivesInstances (core.js:12181)
at Module.ɵɵelementStart (core.js:21434)
at SignupComponent_Template (signup.component.html:1)
at executeTemplate (core.js:12141)
at renderView (core.js:11911)
defaultErrorLogger @ core.js:6272
handleError @ core.js:6325
(anonymous) @ core.js:43091
invoke @ zone-evergreen.js:364
run @ zone-evergreen.js:123
runOutsideAngular @ core.js:41772
(anonymous) @ core.js:43088
invoke @ zone-evergreen.js:364
onInvoke @ core.js:41938
invoke @ zone-evergreen.js:363
run @ zone-evergreen.js:123
(anonymous) @ zone-evergreen.js:857
invokeTask @ zone-evergreen.js:399
onInvokeTask @ core.js:41916
invokeTask @ zone-evergreen.js:398
runTask @ zone-evergreen.js:167
drainMicroTaskQueue @ zone-evergreen.js:569
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:552
scheduleTask @ zone-evergreen.js:388
scheduleTask @ zone-evergreen.js:210
scheduleMicroTask @ zone-evergreen.js:230
scheduleResolveOrReject @ zone-evergreen.js:847
then @ zone-evergreen.js:979
bootstrapModule @ core.js:42948
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:78
0 @ main.ts:12
__webpack_require__ @ bootstrap:78
checkDeferredModules @ bootstrap:44
webpackJsonpCallback @ bootstrap:31
(anonymous) @ main.js:1
main.ts:12 Error: NodeInjector: NOT_FOUND [ControlContainer]
at getOrCreateInjectable (core.js:5906)
at Module.ɵɵdirectiveInject (core.js:21251)
at NodeInjectorFactory.NgControlStatusGroup_Factory [as factory] (forms.js:1073)
at getNodeInjectable (core.js:6037)
at instantiateAllDirectives (core.js:12965)
at createDirectivesInstances (core.js:12181)
at Module.ɵɵelementStart (core.js:21434)
at SignupComponent_Template (signup.component.html:1)
at executeTemplate (core.js:12141)
at renderView (core.js:11911)**
如果您使用 ReactiveFormsModule 和没有 FormGroup 的 <form>
元素,即您需要在绑定后使用表单,如 [formGroup]="myForm".