【发布时间】:2018-08-23 18:12:45
【问题描述】:
我正在尝试生成一个动态表单,该表单将创建动态数量的问题。我有一个父组件、一个子列表组件和一个寒冷组件,您可以在下面看到。 尝试生成页面时,我遇到了如下所示的错误。 请注意,它正在渲染第一个元素,并且在索引 1 处失败。
这是父模板
<pif-question-list
[questions]="pifQuestions"
[parentFormGroupName]="prefundingForm">
</pif-question-list>
这是子列表:
<div
class="question-container"
*ngFor="let question of questions;let idx=index;">
<pif-question-detail
[question]="question"
[questionControls]='this.parentFormGroupName?.controls?.questions'>
</pif-question-detail>
</div>
这是孩子:
<div
class="form-row"
formArrayName="answerTypes">
<ng-container
*ngFor="let answerType of question.answerTypes;let idx=index;"
[formGroupName]="idx">
</div>
这是错误:
Uncaught Error: Cannot find control with path: 'answerTypes -> 1'
at _throwError (forms.js:1591)
at setUpFormContainer (forms.js:1573)
at FormGroupDirective.push../node_modules/@angular/forms/fesm5/forms.js.FormGroupDirective.addFormGroup (forms.js:4325)
at FormGroupName.push../node_modules/@angular/forms/fesm5/forms.js.AbstractFormGroupDirective.ngOnInit (forms.js:1698)
at checkAndUpdateDirectiveInline (core.js:9042)
at checkAndUpdateNodeInline (core.js:10306)
at checkAndUpdateNode (core.js:10268)
at debugCheckAndUpdateNode (core.js:10901)
at debugCheckDirectivesFn (core.js:10861)
at Object.eval [as updateDirectives] (QuestionDetailComponent.html:9)
【问题讨论】:
-
请发布您的反应式表单的结构,以便更清晰。
标签: angular typescript reactive-programming angular-reactive-forms dynamic-forms