无法从'@angular/forms'导入“导入FormGroup,FormControl [重复]
Posted
技术标签:
【中文标题】无法从\'@angular/forms\'导入“导入FormGroup,FormControl [重复]【英文标题】:Getting this error "Cannot import "import FormGroup, FormControl from '@angular/forms'" after adding angular Reactive form [duplicate]无法从'@angular/forms'导入“导入FormGroup,FormControl [重复] 【发布时间】:2020-08-24 15:07:08 【问题描述】:我想在 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)**
【问题讨论】:
请提供一些代码 也许这个帮助:***.com/questions/48212949/… 【参考方案1】:如果您使用 ReactiveFormsModule 和没有 FormGroup 的 <form>
元素,则会引发错误,即您需要在绑定后使用表单,例如 [formGroup]="myForm"。
【讨论】:
以上是关于无法从'@angular/forms'导入“导入FormGroup,FormControl [重复]的主要内容,如果未能解决你的问题,请参考以下文章
Angular 5:找不到模块:错误:无法解析“@angular/forms/src/validators”