When creating reactive forms with Angular, we have two options available. The most documented one is to inject the FormBuilder
service and use it to generate your form’s structure:
FormBuilder
makes perfect sense for forms that contain lots of elements. This service gives us methods that are factories for the following syntax, which is a lot more verbose:
Now, if you have a simple form with just one or two form controls, you don’t need FormBuilder
. Declaring your FormControl
“manually” is actually more manageable that way:
You can find an example of a single FormControl
with custom validation here on Stackblitz.