Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Angular NG01101: What to Return From an Async Validator

Angular NG01101 signals that an async validator returned a synchronous value or otherwise violated its return contract. Learn the required result shape, where to register the validator, and how to handle Observable completion and request errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular error NG01101 means an async validator returned the wrong kind of value. It must return a Promise or Observable that resolves or emits null for a valid value or a ValidationErrors object for an invalid one. A plain boolean, null, or error object returned directly does not satisfy the contract.

What NG01101 means

Angular expects an async validator to produce its result asynchronously, even when the result indicates success. For an Observable-based validator, that means emitting either null or an error map; for a Promise-based validator, it means resolving to one of those values. See Angular’s NG01101 error reference and the AsyncValidator API.

As an Amazon Associate I earn from qualifying purchases.

  • null means validation succeeded.
  • A ValidationErrors object means validation failed. Its keys identify the validation error, and its values can provide related details.

For example, an Observable validator can return of({ notTen: true, requiredValue: 10 }) when a value is invalid and of(null) when it is valid. Both branches return an Observable; returning the object or null directly is the mistake.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check how the validator is registered

In a reactive form, a FormControl constructor accepts synchronous validators as its second argument and async validators as its third. If a synchronous validator is placed in the async-validator position, Angular may report NG01101. The FormControl API documents the constructor arguments.

new FormControl(initialValue, syncValidators, asyncValidators)

Angular runs async validators only after all synchronous validators pass, as explained in its form validation guide. This ordering can help distinguish a registration problem from a return-value problem.

Fix the return value on every branch

Inspect the value each code path actually returns, including success, failure, and early-return branches. A TypeScript annotation does not convert a synchronous value into a Promise or Observable at runtime.

Observable example

const validator: AsyncValidatorFn = (control) =>
  service.check(control.value).pipe(
    map((isInvalid) => isInvalid ? { unavailable: true } : null),
    take(1),
    catchError(() => of(null)), // Choose this policy deliberately.
  );

This illustrative pattern maps a service result to ValidationErrors | null and limits the stream to one emission. Adapt the service call and error policy to your application; the example is not a universal implementation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Promise example

A Promise-based validator must likewise resolve to the error map or null. Returning a direct boolean from a function declared as an async validator is still wrong; wrap the asynchronous operation in a Promise and resolve its result in the required form.

Make Observable validators complete

Angular expects an async-validator Observable to complete. Until validation finishes, the control can remain pending. If a service returns a stream that stays open, limit or otherwise complete it. Angular’s form guide lists operators such as first, last, take, and takeUntil as ways to make an Observable finite.

Choose what happens when the request fails

A network or service error is separate from whether the entered value is valid, so decide explicitly how the application should treat it. Angular’s guide demonstrates catchError returning of(null); that policy treats the failed request as successful validation. An application can instead return an Observable of a validation error. Choose based on the consequences of allowing or blocking submission when the check cannot run.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Distinguish synchronous and asynchronous validators

Use a synchronous validator for checks that can decide from the control value immediately, such as a format rule. Use an async validator when the decision depends on asynchronous work, such as a service response. The difference affects both the validator’s return contract and where it is registered in a reactive FormControl. Angular documents the asynchronous contract in its AsyncValidatorFn API; this is a next.angular.dev API URL, while the error reference and guide linked above are on angular.dev.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.