Validating an Input
The FormControl constructor has three optional parameters. The first is a default value for the form element. The type of this parameter is also used to inform Angular about what sort of form element to expect to be attached to this FormControl. The second and third parameters are arrays that contain the synchronous and asynchronous validation logic, respectively, for this individual element. Each validation rule is a function that is given the form control element (this is where we use the AbstractControl that was imported earlier) and then returns either null, if there’s no error, or an object containing details about what’s gone wrong. Let’s take a look at how we might implement a validator for the phone number.
Built-In ... |
---|
Get Build Reactive Websites with RxJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.