I do have quantity dropdown in my form array which is having quantityList. List of options in dropdown is varying according to selection of product.
Can push quantityList as static data array in formarray without any formcontrol.
HTML file
ngOnInit() {
this.orderForm = new FormGroup({
items: new FormArray([])
});
}
createItem(): FormGroup {
return new FormGroup({
productName: new FormControl(),
price: new FormControl(),
quantity: new FormControl(),
quantityList: ["1","2","3"] // ['1','2'] , ['1']
});
}
addItem(): void {
this.items = this.orderForm.get('items') as FormArray;
this.items.push(this.createItem());
}
TS file
ngOnInit() {
this.orderForm = new FormGroup({
items: new FormArray([])
});
}
createItem(): FormGroup {
return new FormGroup({
productName: new FormControl(),
price: new FormControl(),
quantity: new FormControl(),
quantityList: ["1","2","3"] // ['1','2'] , ['1']
});
}
addItem(): void {
this.items = this.orderForm.get('items') as FormArray;
this.items.push(this.createItem());
}
stackblitz URL : https://stackblitz.com/edit/form-array-angular-xt8uhx?file=src%2Fapp%2Fapp.component.html