是什么导致“control.registerOnChange 不是函数"?错误 [英] What causes the "control.registerOnChange is not a function" error
问题描述
我有一个使用反应式表单方法的表单.该表单在我的哈巴狗中创建如下:
I have a form using the reactive form approach. The form is created as follow in my pug:
form([formGroup]='form', novalidate='', (ngSubmit)='postSurvey(form.value, form.valid)')
一切正常,除非我尝试更改 javascript 部分中的表单(它是一个 FormArray
).我收到以下错误:
Everything works fine except when I try to change the form (which is a FormArray
) in the javascript part. I get the following error:
EXCEPTION: Error in http://localhost:8080/app/components/fillForm.template.html:0:326 caused by: control.registerOnChange is not a function
core.umd.js:3497 TypeError: control.registerOnChange is not a function
at setUpControl (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:1634:17)
at eval (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4752:25)
at Array.forEach (native)
at FormGroupDirective._updateDomValue (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4747:29)
at FormGroupDirective.ngOnChanges (http://localhost:8080/node_modules/@angular/forms/bundles/forms.umd.js:4616:22)
at Wrapper_FormGroupDirective.ngDoCheck (/ReactiveFormsModule/FormGroupDirective/wrapper.ngfactory.js:30:18)
at View_FillFormComponent2.detectChangesInternal (/AppModule/FillFormComponent/component.ngfactory.js:275:32)
at View_FillFormComponent2.AppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12592:18)
at View_FillFormComponent2.DebugAppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12739:48)
at ViewContainer.detectChangesInNestedViews (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12850:41)
at CompiledTemplate.proxyViewClass.View_FillFormComponent0.detectChangesInternal (/AppModule/FillFormComponent/component.ngfactory.js:64:14)
at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12592:18)
at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12739:48)
at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:12577:22)
at CompiledTemplate.proxyViewClass.View_FillFormComponent_Host0.detectChangesInternal (/AppModule/FillFormComponent/host.ngfactory.js:29:19)
我更改表单的代码非常复杂,我无法简化它或在 plunker 中重现它.不仅仅是直接找到解决方案(这么少的细节太难了),我想了解这个错误意味着什么?以及可能导致此错误的原因.
My code to change the form is quite complex and I can't simplify it or reproduce it in a plunker. More than finding directly the solution (it's too difficult with so little details), I would like to understand what this error means? And what might cause this error.
我发现错误发生在我的 HTML 中的 [formGroup]='form'
.
I have figured out that the error occurs at [formGroup]='form'
in my HTML.
任何建议都会有所帮助.
Any suggestion will help.
更新我在 angular github 这里提交了一个问题 并在此处提出了一个修复方案,重现该问题的plunker是这里
Update I have filed an issue on angular github here and have proposed a fix here The plunker to reproduce the issue is here
推荐答案
是的,该错误消息有点神秘,但是如果您使用 FormBuilder,当您向FormGroup 在您的组件中并将其命名为 "A",但随后忘记将带有 formControlName="A" 的输入添加到您的模板中,或者预期输入的 formControlName 不是 A,或者为空,或者不存在.
Yes, that error message is a bit cryptic, but if you use FormBuilder, you would see this when you added a control to FormGroup in your component and named it "A", but then either forgot to add input with formControlName="A" to your template, or formControlName for the intended input is not A, or empty, or not present.
基本上,它说:我无法将 FormGroup 中的控件与模板中的控件相匹配".
Basically, it says: "I cannot match the control I have in FormGroup to the control in the template".
这篇关于是什么导致“control.registerOnChange 不是函数"?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!