angular - 使用 Angular 的动态响应式表单
问题描述
我创建了一个动态反应表单,除了第一项FormArray
显示为空外,它工作正常。
数组的后续项目生成良好。如果我在生成其他项目后删除第一个项目,则数据将正确保存。
我在控制台上看到以下错误并尝试寻找解决方案,但根据网络上的各种答案,我已经正确完成了。
ERROR Error: Cannot find control with path: 'contentBoxes -> 0 -> contentType' Unable to display error. Open your browser's console to view. Angular is running in the development mode. Call enableProdMode() to enable the production mode. ERROR Error: Cannot find control with path: 'contentBoxes -> 0 -> revenueShare' Unable to display error. Open your browser's console to view.
代码可以在这里查看和运行:https ://stackblitz.com/edit/angular-ui5n8c
非常感谢您的帮助。
解决方案
您将函数的引用放在索引 0: this.buildGroup
; 那当然应该是:this.buildGroup()
。这样,将调用函数并返回实际对象。所以你的问题是,该功能没有被执行。
所以总结一下:
```
buildArray(): FormArray {
this.contentBoxes = this._fb.array([
this.buildGroup() // <---- notice the () I added, these are needed!
//this._fb.control('')
]);
return this.contentBoxes;
}
```
推荐阅读
- python - Python/exchangelib:如何在通讯录中搜索联系人
- reactjs - React JS - 在标签点击时清除子表单
- sql-server - 将查询结果带到新表中,然后在 SQL Server 中进行查询
- docker - 如何通过manager访问swarm网络中不同系统的docker容器?
- cmd - 如何在 JMeter 中同时运行两个 .jmx 文件并为这两个文件创建一个报告?
- node.js - Windows 节点中 process.env.TZ = 'UTC' 的解决方案?
- google-chrome - 访问网站的辅助功能树
- git - 通过 HTTP 推送到 Heroku
- python - 使用 Python 进行 GCP BigQuery 的 Google OAuth 2.0
- php - php文件上传代码在ubuntu中使用mysql数据库无法正常工作