Before we move on, we need to implement validations for loginForm. As we implement more forms in Chapter 10, Angular App Design and Recipes, you will realize that it gets tedious, fast, to repeatedly type out form validations in either template or reactive forms. Part of the allure of reactive forms is that it is driven by code, so we can easily extract out the validations to a shared class, unit test, and reuse them:
- Create a validations.ts file under the common folder
- Implement email and password validations:
src/app/common/validations.tsimport { Validators } from '@angular/forms'export const EmailValidation = [Validators.required, Validators.email]export const PasswordValidation = [ Validators.required, Validators.minLength(8), ...