简体   繁体   English

嵌套数组形式(Angular2)

[英]Nested Array Form (Angular2)

i'am creating nested form array that structured like this 我正在创建结构如下的嵌套表单数组 在此处输入图片说明

the form got an error when i want to add array into objects 当我想向objects添加数组时,表单出现错误

在此处输入图片说明

here is the plnkr 这是plnkr

if you have difficulty to understand,please tell me. 如果您难以理解,请告诉我。

The only error you seem to have in your plunker, is the iteration of the surveys array, instead of: 你似乎在你的plunker唯一的错误,是的迭代surveys阵列,而不是:

*ngFor="let survey of myForm.controls.objects.controls; let j=index"

it should be: 它应该是:

*ngFor="let survey of object.controls.surveys.controls; let j=index"

where object refers to the iterations of objects form array in the higher level iteration. 其中object指的是迭代objects以在所述更高级别的迭代的数组。

So now when clicking Line End button in the Survey tab is working fine, see the forked Plunker 因此,现在在“ Survey选项卡中单击“ Line End按钮时,它可以正常工作,请参阅叉状柱塞

See Your code the error states that the surveys object is not binded while looping.You need to loop properly in HTML .Check the below code 请参阅您的代码,错误指出循环时未绑定测量对象。您需要在HTML中正确循环。检查以下代码

     <div *ngFor="let item of formvalue.objects; let i=index">
    <ul>
       <li>{{item.date}}</li>
    </ul>
    <div *ngFor="let survey of item.surveys ; let j=index">
    <ul>
      <li>{{survey.br_0}} </li>
    </ul>
  </div>
  </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM