From 25739c83e2b224b593d8f645ef01c45574098b30 Mon Sep 17 00:00:00 2001 From: Tim Bowersox <11789189+t-bowersox@users.noreply.github.com> Date: Wed, 19 Jan 2022 19:39:24 -0500 Subject: [PATCH] docs: add note about using NG_ASYNC_VALIDATORS (#44764) When setting up an async validator in a template-driven form, it's necessary to register the directive with NG_ASYNC_VALIDATORS instead of NG_VALIDATORS. This was not mentioned in the docs. PR Close #44764 --- aio/content/guide/form-validation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/aio/content/guide/form-validation.md b/aio/content/guide/form-validation.md index ed1306734e5..36be9964611 100644 --- a/aio/content/guide/form-validation.md +++ b/aio/content/guide/form-validation.md @@ -285,6 +285,7 @@ These are very similar to their synchronous counterparts, with the following dif * The `validate()` functions must return a Promise or an observable, * The observable returned must be finite, meaning it must complete at some point. To convert an infinite observable into a finite one, pipe the observable through a filtering operator such as `first`, `last`, `take`, or `takeUntil`. +* In template-driven forms, register your validator directive with the `NG_ASYNC_VALIDATORS` provider instead of `NG_VALIDATORS`. Asynchronous validation happens after the synchronous validation, and is performed only if the synchronous validation is successful. This check lets forms avoid potentially expensive async validation processes (such as an HTTP request) if the more basic validation methods have already found invalid input.