Creating forms dynamically
Creating a good form requires quite a bit of code. Regardless of whether you’re using the template-driven or reactive approach, you need a lot of HTML; you need to define the model, add validators, and additional logic such as the submit behavior.
You could use a base class for some of the shared functionality, but you can also build a dynamic form, which will dynamically build the form based on a JSON input. In this section, we will build a simple example of a dynamic form. You can extend the dynamic form to fit your specific needs. For example, you might want to fetch the configuration from an external source or support additional validators.
To start our dynamic form, create a new form component named dynamic-form
in your expenses-registration-forms
library. Next, create a dynamic-control.interfaces.ts
file. I will create the new interface inside the component folder, but you can locate all interfaces in a designated folder or use any other...