简体   繁体   English

无法以 Angular 形式的嵌套形式读取 null 的属性(读取“控件”)

[英]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,请帮助我解决此错误

StackBlitz link 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.

相关问题 Angular 错误:无法读取 null 的属性(读取“控件”) - Angular Error: Cannot read properties of null (reading 'controls') Angular(无法读取 null 的属性(读取“addControl”)-更改子组件中的表单值 - Angular (Cannot read properties of null (reading 'addControl') - Change form value in child component angular 中的嵌套动态表单 - 无法读取未定义的属性“控件” - Nested dynamic form in angular - Cannot read property 'controls' of undefined 角度:嵌套形式“无法读取null的属性&#39;length&#39;” - Angular: nested form “Cannot read property 'length' of null” Angular:无法读取 null 的属性(读取“cannotContainSpace”) - Angular: Cannot read properties of null (reading 'cannotContainSpace') Angular 14:无法读取未定义的属性(读取“控件”) - Angular 14: Cannot read properties of undefined (reading 'controls') 类型错误:无法读取未定义的属性(读取“控件”)<jasmine> 在角度</jasmine> - TypeError: Cannot read properties of undefined (reading 'controls') at <Jasmine> in Angular TypeError:无法读取null angular的属性&#39;form&#39; - TypeError: Cannot read property 'form' of null angular 无法以 Angular 形式读取 null 的属性“错误” - Cannot read property 'errors' of null in Angular form 错误:无法读取未定义的属性(读取“headerCell”) - 在 angular 材料表中创建反应形式 - Error: Cannot read properties of undefined (reading 'headerCell') - Creating reactive form inside a angular material table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM