I am using angular formbuilder to create a nested form. How do I set nested form quantity field value for each form group within updateValue() function in following code.
ngOnInit() {
this.fastPostingForm = this.fb.group({
Charges: this.fb.array([
this.initCharge()
])
});
}
initCharge(){
return this.fb.group({
room: ['', Validators.required],
amount: ['', Validators.required],
quantity: ['', Validators.required],
});
}
UpdateValue(i) {
this.fastPostingForm.controls.Charges[i].controls['quantity'].setValue(2); // This is not working
}
controls?this.fastPostingForm.controls.Charges.controls[i].controls['quantity'].setValue(2);Maybe consider to pass the nested group as parameter instead of index, so that you don't need to go nuts with those long paths :)