Angularjs Angular 2 AbstractControl运行时
我按照这个答案来实现Angular 2应用程序的“添加更多”功能。与此答案关联的项目已上载到。不幸的是,要开始这个项目,我必须对这些行进行注释Angularjs Angular 2 AbstractControl运行时,angularjs,node.js,angular,npm,runtime,Angularjs,Node.js,Angular,Npm,Runtime,我按照这个答案来实现Angular 2应用程序的“添加更多”功能。与此答案关联的项目已上载到。不幸的是,要开始这个项目,我必须对这些行进行注释 this.form.controls.payOffs.push(this.createPayOffFormGroup(po)) this.form.controls.payOffs.push(this.createPayOffFormGroup(emptyPayOff)); console.log("Added New Pay Off", this.fo
this.form.controls.payOffs.push(this.createPayOffFormGroup(po))
this.form.controls.payOffs.push(this.createPayOffFormGroup(emptyPayOff));
console.log("Added New Pay Off", this.form.controls.payOffs)
this.form.controls.payOffs.removeAt(index);
并键入“npm start”,然后取消注释。如果我不对其进行注释,则会出现以下错误:
app/Components/companyInsertion.component.ts(37,28):错误TS2339:类型“{[key:string]:AbstractControl;}”上不存在属性“payofs”。
app/Components/companyInsertion.component.ts(56,24):错误TS2339:类型“{[key:string]:AbstractControl;}”上不存在属性“payofs”。
app/Components/companyInsertion.component.ts(57,57):错误TS2339:类型“{[key:string]:AbstractControl;}”上不存在属性“payofs”。
app/Components/companyInsertion.component.ts(63,24):错误TS2339:类型“{[key:string]:AbstractControl;}”上不存在属性“payofs”
所以,据我所知,这段代码只在运行时起作用。我尝试了这个解决方案,但似乎没有帮助:
通过改变
this.form.controls.payOffs.push(this.createPayOffFormGroup(po))
到
所以现在我可以运行这个应用程序了,但我非常不喜欢每次启动服务器时都要发表评论。有什么解决方案吗?我找到的唯一解决方案是:
(this.form.controls as any)['payOffs'].value.push(this.createPayOffFormGroup(po))
我找到的唯一解决方案是:
(this.form.controls as any)['payOffs'].value.push(this.createPayOffFormGroup(po))
这很糟糕,但我发现解决这些类型脚本错误的唯一方法是先将其转换为
FormArray
。这真的很烦人,我希望Angular 2在未来的打字更新可能有助于解决这个问题
(<FormArray> this.form.find('pay_offs')).push(this.createPayOffFormGroup(po))
(this.form.find('pay_offs')).push(this.createPayOffFormGroup(po))
这很糟糕,但我发现解决这些打字错误的唯一方法是先将其转换为格式数组。这真的很烦人,我希望Angular 2在未来的打字更新可能有助于解决这个问题
(<FormArray> this.form.find('pay_offs')).push(this.createPayOffFormGroup(po))
(this.form.find('pay_offs')).push(this.createPayOffFormGroup(po))
这是可行的,但它只是一种解决办法。解决方案是什么?这是可行的,但它只是一个解决办法。解决办法是什么?