Ever felt repetitive creating forms in your Angular Application? Let’s fix it.

Intro

During the Front-end development days it feels like there is a lot of repetitive code which I have to write to design my forms which are almost all the time very close one to another.

I’ve been recently looking into ways of automating it. The furthest I wanted to go was to have some kind of interface between a more friendly modelling object as well as to an interface to link my objects to the Angular Modelling Universe.

This way, I discovered there is already a library that could do it for me formly. But looking over their documentation I realized this is a little bit more than I wanted.

As a result, I ended writing my own form generator. You’ll see that except for two or three pitfalls this is rather easy to achieve.

Foreground

I’ll be using Angular Materials to generate my forms.

I have two tips to share about their design. It can be difficult to change the colors or design a theme for them. You’ll see the documentation on their side is rather not the best on this subject. My piece of advice, use  https://materialtheme.arcsine.dev/. In case you don’t know exactly what colors to use but you have a slight idea about it, I recommend using  https://www.cssportal.com/css-color-converter/0000D8. In the end you’ll definitely discover some very cool Angular Material Theme which you can even share with others.

Getting Started

First of all, we’ll organize our application on modules. When it comes to Angular I always split the code in presentation and business. From where I’m standing, presentation means those components that deal with UX functionality, they can work by themselves but they don’t make sense for a user taken alone; business are those components that configure and group together presentation through a context.

#angular-forms #angular #typescript #angular-formly

Angular Form Generator & Pitfalls
1.50 GEEK