[英]Cannot read properties of null (reading 'controls') in Nested Form of Angular Form
I'm new to angular. Working on creating nested form in angular where I'm facing difficulties for getting controls of some fields based on the JSON structure shown below where I'm facing difficulties in getting control assetsList -> description section我是 angular 的新手。致力于在 angular 中创建嵌套表单,我在获取基于如下所示的 JSON 结构的某些字段的控件时遇到困难,在获取控制资产列表 -> 描述部分时遇到困难
data = {
headline: [
{
language: 'en',
headlineText: 'example headline',
},
],
bodyText: [
{
language: 'en',
bodyText: 'example bodytext',
},
],
location: {
name: 'mkontheway',
openingHours: [
{
day: 'Mon-frd',
timing: '10.00PM-9AM',
},
],
address: {
postCode: 'test',
country: 'test',
},
},
assetsList: [
{
description: [
{
language: 'En',
text: 'Sports News Updated',
},
],
assetType: 'Description',
assetLink: 'NewsLink',
filePath: 'Not yet fill',
},
],
};
I created a Stackblitz for the same please help me for solving this error我为此创建了一个 Stackblitz,请帮助我解决此错误
assetsListDescriptionFormData can not be a getter because you need indicate the "index" of the assetsList -you has a FormArray inside another FormArray- else a function that you pass an index assetsListDescriptionFormData不能是 getter,因为您需要指示 assetsList 的“索引”-您在另一个 FormArray 中有一个 FormArray-否则您传递索引的 function
getAssetsListDescriptionFormData(index:number) {
return <FormArray>this.assetsListFormData.at(index).get('description');
}
And use并使用
<div formArrayName="description" style="position: relative;">
<div *ngFor="let description of
getAssetsListDescriptionFormData(assetsListGroup).controls;
let assetsListDescriptionGroup=index">
<div class="form-fields-wrapper" [formGroupName]="assetsListDescriptionGroup">
...
</div>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.