angular - FormArray 中的 Angular FormGroup 省略了特定键
问题描述
我正在使用 Angular 8 网络应用程序。
我有一个 FormGroup,其中包含一些控件和一个名为params
FormArray 的键。该 FormArray 包含 FormGroups。
问题是我用 js 对象创建了这些 FormGroups (params) 并且它们丢失了 key name
。它非常奇怪。
我将发布有用的代码:
在这里,我使用来自后端的数据创建了一个预加载的表单:
public buildPreLoadedForm() {
this.form = this.formBuilder.group({
...this.currentFormula,
params: this.formBuilder.array([]),
formulaResult: []
});
this.updateFormulaParams();
}
public updateFormulaParams() {
for (const param of this.currentFormula.params) {
this.formParams.push(this.createFormulaParam(param));
}
}
public createFormulaParam(formulaParam: FormulaParam) {
return this.formBuilder.group({...formulaParam});
}
“currentFormula”中的参数是这样的:
const param: FormulaParam = {
ID: 0,
CreatedAt: null,
UpdatedAt: null,
DeletedAt: null,
name: 'val' + num,
type: 'number'
};
我在表单中推送新参数,这样做:
(this.form.get('params') as FormArray).push(this.createFormulaParam(param));
我创建的参数看起来像:
但是,在表单内部(在推送之后),我得到了:
我要失去name
财产了!这对我来说没有意义。
谢谢!
解决方案
推荐阅读
- html - 修复 bootstrap 4 中的菜单问题,避免每个子下拉菜单相互重叠
- java - 为什么我在 LinkedList 中的 add() 方法不起作用?
- r - facet 一组多面图
- python - 在 python 中,/ 运算符在以下代码中做了什么
- javascript - 假变量不验证为假
- typescript - Windows 10 上的 Visual Studio 项目
- android - 将gridview替换为recyclerview
- maven - 无法使用 gitlab 解析引导索引 maven 声纳分析中的条目
- cassandra - Cassandra 在连接 Sails.js 时抛出错误
- java - 错误:找不到符号方法 setLatestEventInfo(Context,CharSequence,CharSequence,PendingIntent)