我正在使用FormArray并且在另一个控件中有控件,但是如何在角度的嵌套控件中添加元素 [英] i am using FormArray and i have controls inside another controls but how can i add element in nested controls in angular

查看:56
本文介绍了我正在使用FormArray并且在另一个控件中有控件,但是如何在角度的嵌套控件中添加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对将数据推送到控件有点困惑,因为我在嵌套控件内使用控件,但我不知道如何在嵌套控件内推送数据 这是我的component.ts代码

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

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

推荐答案

以下是有效示例,请检查链接

Here is the working example, Please check the link

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

这篇关于我正在使用FormArray并且在另一个控件中有控件,但是如何在角度的嵌套控件中添加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆