Angular 角度形式数组,第一个索引始终为空
请协助,我正在尝试使用角度形式数组查看从组件到视图的数据。以下解决方案:。帮助我,但现在我遇到一个问题,表单数组的第一个索引始终为空,并且我收到以下错误:Angular 角度形式数组,第一个索引始终为空,angular,angular5,angular-reactive-forms,Angular,Angular5,Angular Reactive Forms,请协助,我正在尝试使用角度形式数组查看从组件到视图的数据。以下解决方案:。帮助我,但现在我遇到一个问题,表单数组的第一个索引始终为空,并且我收到以下错误: ERROR Error: Cannot find control with path: '[object Object] -> 0' at _throwError (forms.js:2432) at setUpFormContainer (forms.js:2405) at FormGroupDirective.addFormGrou
ERROR Error: Cannot find control with path: '[object Object] -> 0'
at _throwError (forms.js:2432)
at setUpFormContainer (forms.js:2405)
at FormGroupDirective.addFormGroup (forms.js:6691)
at FormGroupName.AbstractFormGroupDirective.ngOnInit (forms.js:2568)
...
Cannot read property 'controls' of undefined
at Object.eval [as updateDirectives]
...
在我的ngOnInit中,我只有以下内容:
this.SectionForm= this.formBuilder.group({
sectionData: this.formBuilder.array([this.buildDevelopmentSector()])
});
this.activatedRoute.params.subscribe(res =>
// get data and push the data to a formArray called sectionDataArray
this.GetDataFromApi(res.requestId)
);
0:
amount:""
percentage:""
name:""
quantity:""
__proto__:Object
1:
amount:1200000
percentage:23
name: "Repo"
quantity:20000
__proto__:Object
length:2
__proto__:Array(0)
该视图包含以下部分:
<div [formGroup] ="SectionForm">
<div [formArrayName]="sectionDataArray">
<div *ngFor="let section of sectionDataArray.controls ; let i = index" [formGroupName]="i">
...
...
...
</div>
你支持的对象有
sectionData: this.formBuilder.array([this.buildDevelopmentSector()])
所以它是sectionData
,但您在这里引用的是sectionDataArray
<div [formArrayName]="sectionDataArray">
将其更改为备份对象所具有的
sectionData
sectionData: this.formBuilder.array([this.buildDevelopmentSector()])
所以它是sectionData
,但您在这里引用的是sectionDataArray
<div [formArrayName]="sectionDataArray">
将其更改为
sectionData
,并从[formarayname]
中删除方括号,或更改为[formarayname]='sectionData'“
:)或在组件sectionData:string='sectionData'
:)上创建属性以对错误进行排序,我收到错误的原因是因为我没有调用或初始化sectionDataArray
onInit。谢谢。基本上我写的是-u引用了未定义的属性。并从[formarayname]
中删除方括号,或更改为[formarayname]='sectionData'“
:)或在组件sectionData:string='sectionData'
:)上创建属性以对错误进行排序,我收到错误的原因是因为我没有调用或初始化sectionDataArray
onInit。谢谢。基本上我写的是——你指的是未定义的属性。