Yadav Abhishek Tejbahadur
Thank you for a great article. I am trying to delegate the create of the form control to DynamicFieldComponent, however I am having some trouble with the initial values of the form - it only seems to see the controls once one of the controls has been touched.
Any ideas what could be happening? Here is a stackblitz that shows the problem:
I made a stackblitz but since I am a current user I am unable to include the link in the post. Here is the id: github-kzuu3x
Hi Dany, I have used above approach and applied a level of nesting to Metadata json. It seems to have performance issue. Did you gave it a try to nest the json.
hi, dany can you please let me know how we can add the custom events like keyup, keydown, blur to the above dynamic forms. Thanks
hello, thank you , very useful writeup. I saved the submitted form in the db as JSON. Now I need to display the form in the UI. How can I get the 'label' for each field in the JSON data. I only have the formControlName : Value in the JSON (getRawValue() from the form is what stored in the db). Please help.
This is a life saver! Thank you so much. I have one follow-up question, I organised my models based on the database schema and in some of the fields I have a group of objects (form group), such as:
{ first_name: {..items}, address: { address_1: {..items}, address_2: {..items}, city: {...items}, } } ...etc
What you described covers first name, but if the object is nested, I'm able to add it in the form so we have the formGroup, and under that we have the formcontrols under the group, but I can't get to reuse the Inputs, the Select etc... field components in this new object. I hope you can help point me in the right direction. Thank you!
How can I update specific components without rebuilding the form again, the situation is when for example you have two selects depending on each other. Dany Paredes
Thank you, Dany because I was searching for a way to build dynamic forms and found and tested your way. It was perfect and practical.
how do you call functions in the dynamic component from the input components?
Thank you Dany for this wonderful article. I am trying to figure out, how you are planning to define/access the events associated with the form controls. For instance, if I want to have a change or blur event attached to the input field, what would be the best place to have it?
How do I get the values from the dynamic fields. I have a button in dynamic-form.component.html and if I click the button I want to get the updated model to the console.
Btw. nice article
Thank you, Dany! This is very practical and uses advanced Angular mechanics. Since switch statement is hard to maintain and some consider them as bad practice, can we create such field components dynamically? I would be really pleased reading another article from you on this topic.
Hi Dany,
I am trying to load select dropdown values via a service call, but the values are not reflecting in the dropdown component. Could you help me with this?
I am calling the service in the
ngOnInitmethod and also creating the form there. When I checked the console, I found that the service is retrieving data after the component is initialized. However, the method that creates the form expects data from the service, but since the data is retrieved after the component initialization, the options are not being rendered in the select component.Can you guide me on how to resolve this?