Performance: Reactive forms vs template forms decision
This affects how quickly the form renders and responds to user input, impacting interaction responsiveness and initial load time.
Reactive form using FormGroup and FormControl with explicit subscriptions to valueChanges.
Template-driven form with many two-way bindings and ngModel directives in the template.| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Template-driven form (complex) | High due to many bindings | Multiple reflows per input | Higher paint cost | [X] Bad |
| Reactive form (complex) | Controlled and minimal | Single reflow per update | Lower paint cost | [OK] Good |
| Template-driven form (simple) | Low | Minimal reflows | Low paint cost | [OK] Good |
| Reactive form (simple) | Extra setup overhead | Minimal reflows | Slightly higher paint cost | [!] OK |
console.log(this.form.value) after setting this.form.controls['email'].setValue('test@example.com')?
this.form = new FormGroup({ email: new FormControl('') });<form #myForm="ngForm"> <input name="username" ngModel> <button type="submit">Submit</button> </form>
Pass the test and this pattern moves unknown