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

余生长醉 提交于 2019-12-24 21:55:51

问题


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


回答1:


Here is the working example, Please check the link

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



来源:https://stackoverflow.com/questions/59324879/i-am-using-formarray-and-i-have-controls-inside-another-controls-but-how-can-i-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!