I'm having an angular app with a form and I'm going to use Reactive forms there. In that form there's a dropdown (Items are loading from the API). If user clicks a dropdown item , it generates a table with two fields (Inputs and label). Number of input items are generated dynamically.
Ex: If user clicks the first item of the dropdown , may be 5 input fields and labels will generate. If user clicks the second item of the dropdown , may be 2 input fields and labels will generate. This is what I tried
ngOnInit() {
this.orderForm = this.formBuilder.group({
tableInputs: this.formBuilder.array([])
})
}
This is the dropdown change function (getting values from API)
dropdownChanged(){
const control = <FormArray>this.orderForm.controls['tableInputs'];
this.apiService.listColumnData(this.selectedTable).subscribe(result=>{
this.columns = result['data'].columns;
control.push(new FormControl(this.columns))
}); }
this is how 'this.columns look like (getting from API)
[{0: display_name: "sales name" , id: 17, name: "sales_name",}]
This is how I try to render the items in view.
<form>
<div [formGroup]="orderForm">
<div formArrayName="tableInputs">
<div *ngFor="let item of orderForm.controls.name; let i=index" >
<input formControlName="tableInputs">
</div>
</div>
</div>
I'm new to Angular Reactive forms. I wasn't able to render the items. Could someone help me on this?