0

I am new to angular so still learning it, it might be simple use case but so far i have been trying to implement it but unable to do it so asking here. I am making an http requests and based on the data received from the http request(array of json objects) i want to create as many forms on the page as there are objects in response array. Any idea how can achive it.this is the data i am getting from http request enter image description here

Have searched a lot and did not find any stackoverflow answer to my given problem, Have been struggling to implement it from 4 days :( Please dont close it i have not been able to figure it out so asking it here. Any hint where to begin and how to proceed is greatly appreciated.

  • What would be the types of the fields of the form, I mean, whether it will be of input type or radio button type or checkbox.... – KAMLESH KUMAR Feb 06 '20 at 07:26
  • @KAMLESHKUMAR i have additional data field which has information about the type of field and the data corresponding to that field –  Feb 06 '20 at 07:33
  • Do you want to put all the forms in single component or want to use one component to each form and then put all these components into a single one – KAMLESH KUMAR Feb 06 '20 at 07:46
  • @KAMLESHKUMAR i want to put all the forms in single component –  Feb 06 '20 at 09:38

1 Answers1

0

it just create an empty formGroup and use addControl

form=new formGroup({}) //decalre an empty form
//with each element of data
this.data.forEach(x=>{
   //according with others properties you add Validators, etc
   this.form.addControl(x.ruleName,new FormControl())
}

but there're a lot of examples in SO e.g. this one, or this or...

Eliseo
  • 50,109
  • 4
  • 29
  • 67