Performance: Validators (required, minLength, pattern)
MEDIUM IMPACT
Form validators affect input responsiveness and rendering updates during user interaction.
this.form = new FormGroup({ username: new FormControl('', [ Validators.required, Validators.minLength(5), Validators.pattern(/^\w+$/) ]) });
this.form = new FormGroup({ username: new FormControl('', { validators: [ () => { if (!this.form.value.username) return { required: true }; if (this.form.value.username.length < 5) return { minLength: true }; if (!/^\w+$/.test(this.form.value.username)) return { pattern: true }; return null; } ] }) });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Custom inline validators with repeated form value access | Multiple per input | Multiple per input | High due to frequent state changes | [X] Bad |
| Angular built-in validators (required, minLength, pattern) | Minimal | Single per input | Low due to optimized checks | [OK] Good |