InterviewHubPRO
Section Overview
Q268

Question 268 of 283

Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)

95%
Angular & Signals (283 Qs)•Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)

How do you optimize the performance of async validators?

Since all validators run after every form value change, it creates a major impact on performance with async validators by hitting the external API on each keystroke. This situation can be avoided by delaying the form validity by changing the updateOn property from change (default) to submit or blur. The usage would be different based on form types,

  1. Template-driven forms: Set the property on ngModelOptions directive
html
  <input [(ngModel)]="name" [ngModelOptions]="{updateOn: 'blur'}">
  1. Reactive-forms: Set the property on FormControl instance
js
  name = new FormControl('', {updateOn: 'blur'});