【问题标题】:Double Nested(Multi-Level) Components Angular2双嵌套(多级)组件Angular2
【发布时间】: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


【解决方案1】:

试试看: question.answerTypes.controls

【讨论】:

  • 谢谢!我没有循环通过控件。很大的帮助!
猜你喜欢
  • 2016-03-01
  • 1970-01-01
  • 2018-05-25
  • 2018-12-13
  • 1970-01-01
  • 2017-03-09
  • 2017-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多