Question presented to candidate: "Our username field calls the server on every keystroke to check availability, and a large search form recomputes results while people are still typing. What is updateOn in reactive forms, and how would it help here?"
What a strong answer should cover:
updateOndecides when the view value is written to the model:'change'(default, every input event),'blur'(when the control loses focus) or'submit'(when the parent form is submitted).- Writing to the model is what triggers validators (including async ones),
valueChangesand the dirty flag, so delaying the write delays all of them. - Set it per control in the options object, or once on a
FormGroup/FormArray, where children inherit it and can override. - Programmatic
setValue/patchValueignoreupdateOn; it only governs values coming from the UI. - Template-driven equivalents:
[ngModelOptions]="{ updateOn: 'blur' }"per field,[ngFormOptions]for the whole form. - Trade-offs:
blurhides errors until focus leaves;submitgives no live feedback, and withsubmitthe control is never marked touched by blur.
Clarifying questions expected:
- "Do users need live feedback while typing, for example a password-strength meter?"
- "Is the cost the validation itself, or something subscribed to valueChanges?"
Code / implementation expected: Yes β three controls with different updateOn values, showing when each value and its validation change.