【问题标题】:I have a formArray and in that formArray I have just formControls, not formGroup, how can I loop trough that controls in html?我有一个formArray,在那个formArray中我只有formControls,而不是formGroup,我怎样才能循环通过html中的控件?
【发布时间】:2023-04-08 15:41:01
【问题描述】:

当我尝试循环通过 formArray 的控件时,我收到一个错误,即 formControlName 必须在 formGroup 中,但我在 formArray 中没有 formGroup。 html中的代码是这样的

enter image description here

在.ts中是这样的

enter image description here

当我没有 formGroup 但 Angular 想提供 formGroup 时,我该如何解决这个问题

【问题讨论】:

  • 你需要在这里添加代码或者尝试在stackblitz上重现

标签: angular


【解决方案1】:

您忘记使用 answers() 方法,该方法强制转换为 FormArray 并避免该(错误)错误。

*ngFor="let answer of answers().controls"

【讨论】:

  • 非常感谢它对我帮助很大。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-14
  • 1970-01-01
  • 2021-04-06
  • 2021-10-25
  • 1970-01-01
相关资源
最近更新 更多