Performance: Showing validation errors
MEDIUM IMPACT
This affects interaction responsiveness and visual stability when users input data and see validation feedback.
template: `<input [(ngModel)]="name" (blur)="validateName()" /> <div [style.visibility]="showError ? 'visible' : 'hidden'">Name is required</div>`; component: { name = ''; showError = false; validateName() { this.showError = !this.name || this.name.length === 0; } }
template: `<input [(ngModel)]="name" /> <div *ngIf="!nameValid">Name is required</div>`; component: { get nameValid() { return this.name && this.name.length > 0; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Validation on every keystroke with *ngIf | High (many DOM toggles) | Multiple reflows per input | High paint cost due to layout shifts | [X] Bad |
| Validation on blur with visibility toggle | Low (few DOM changes) | Single reflow on blur | Low paint cost, stable layout | [OK] Good |