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.

4
  • 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.... Commented Feb 6, 2020 at 7:26
  • @KAMLESHKUMAR i have additional data field which has information about the type of field and the data corresponding to that field Commented Feb 6, 2020 at 7: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 Commented Feb 6, 2020 at 7:46
  • @KAMLESHKUMAR i want to put all the forms in single component Commented Feb 6, 2020 at 9:38

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.