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