Custom Validators
In this lesson, we'll learn how to write a custom validator.
We'll cover the following...
We'll cover the following...
It’s time to get to the heart of this section, which is writing custom validators. In some cases, you’ll want to create a validator when the validators that come bundled with Angular won’t suffice.
The validator we’ll be creating will check if the passwords from both input fields match. This will be a challenge because validators are typically applied to a single input. We’ll look at how we can use a validator on multiple inputs at the same time.
Here is an overview of the steps we’ll go through to accomplish this:
- Generate a class for the validator
- Implement the
Validator
interface on the class - Define a
validate
method in the class - Return either
null
or an object with the error
We’ll talk more ...