Performance: FormGroup for grouping controls
MEDIUM IMPACT
FormGroup affects how Angular manages and updates multiple form controls together, impacting rendering and change detection performance.
const form = new FormGroup({ userInfo: new FormGroup({ name: new FormControl(''), email: new FormControl(''), age: new FormControl('') }) }); // Template binds to userInfo FormGroup, reducing separate updates
const form = new FormGroup({ name: new FormControl(''), email: new FormControl(''), age: new FormControl('') }); // In template, binding each control separately with individual change detection triggers
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Individual FormControls without grouping | Multiple separate updates | Multiple reflows per control | Higher paint cost due to frequent updates | [X] Bad |
| Grouped FormControls inside a FormGroup | Batched updates in one group | Single reflow per group update | Lower paint cost due to fewer updates | [OK] Good |