#132 Creating a Custom Async Validator | Reactive Forms | A Complete Angular Course

Опубликовано: 14 Сентябрь 2024
на канале: procademy
4k
83

In this lecture you will learn what is an async validator and how to create & use it on a reactive form. Creating an async validator is very similar to creating a sync validator. The only difference is that, async validator either returns a promise or an observable. Also remember that, angular does not provide any built in async validator. But it allows us to create an async validator.

We use the async validator when we need to send an HTTP call to the server to check if the data is valid. Creating a Async Validator is simple as creating a function, which must obey the following rules:
1. The function must return either an observable or a promise
2. Return null for valid, or an ValidationErrorCode if the input is invalid

Let's understand async validator with a simple example, in this lecture.

YOU CAN DOWNLOAD THE STARTUP PROJECT FROM HERE:

YOU CAN DOWNLOAD THE FINAL PROJECT FROM HERE: