简体   繁体   English

我正在使用 FormArray 并且我在另一个控件中有控件但是我如何在角度的嵌套控件中添加元素

[英]i am using FormArray and i have controls inside another controls but how can i add element in nested controls in angular

i am little confuse about push data into control because i using control inside nested control i have no idea how i push data inside the nested control this is my component.ts code我对将数据推送到控件中有点困惑,因为我在嵌套控件中使用控件我不知道如何将数据推送到嵌套控件中这是我的 component.ts 代码

 mileStoneForm:FormGroup;
 constructor(private fb:FormBuilder) {
 this.mileStoneForm = this.fb.group({
  milestone:this.fb.array([])
 });


  createMilestone()
  {
  return this.fb.group({
    name:[''],
    date:[''],
    description:[''],
    value:[''],
    approval:[''],
    deliverable:this.fb.array([
      this.createMilestoneDeliverable()
    ])
  });
 }


   createMilestoneDeliverable()
  {
  return this.fb.group({
    title:[''],
    description:[''],
    excluded:['']
  });
 }


addNewDeliverable()
 {
return (this.mileStoneForm.get('milestone').get('deliverable') as 
FormArray).controls.push(this.createMilestoneDeliverable());
 }

this add function is used to store data in deliverable field i want to push this.createMilestoneDeliverable() function data into deliverable field help me guys i am so confuse i can not fix it with myself此添加函数用于在可交付字段中存储数据我想将 this.createMilestoneDeliverable() 函数数据推送到可交付字段帮助我伙计们我很困惑我无法自己修复它

Here is the working example, Please check the link这是工作示例,请检查链接

https://stackblitz.com/edit/angular-ou6dje https://stackblitz.com/edit/angular-ou6dje

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

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