1

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

5
  • Can this help you return (this.mileStoneForm.get(['milestone','deliverable']) as FormArray).push(this.createMilestoneDeliverable()); ? Commented Dec 13, 2019 at 18:44
  • @Ashot Aleqsanyan when i am adding new row into deliverable it,s give me this erro in console ERROR TypeError: Cannot read property 'push' of null Commented Dec 14, 2019 at 6:33
  • Hello Please can you include the createMilestone function call and mileStoneForm form in your question Commented Dec 14, 2019 at 9:28
  • I see updated answer and in your current example you have not any deliverable in your form and your milestone is the formArray instead of formGroup Commented Dec 14, 2019 at 12:25
  • can you refine my code and comment it to me Commented Dec 14, 2019 at 12:37

1 Answer 1

0

Here is the working example, Please check the link

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.