Performance: Loading states and error patterns
MEDIUM IMPACT
This concept affects how quickly users see feedback during data fetching and error handling, impacting perceived responsiveness and visual stability.
template: `<div aria-live="polite">{{ isLoading ? 'Loading...' : data }}</div>` component: fetchData() { this.isLoading = true; this.http.get(...).subscribe(res => { this.data = res; this.isLoading = false; }); }
template: `<div *ngIf="isLoading">Loading...</div><div *ngIf="!isLoading">{{data}}</div>` component: fetchData() { this.isLoading = true; this.http.get(...).subscribe(res => { this.data = res; this.isLoading = false; }); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Conditional *ngIf loading/error blocks | Adds/removes nodes | 2+ per toggle | High due to layout shifts | [X] Bad |
| Single container with text swap | Text content change only | 1 per toggle | Low, stable layout | [OK] Good |