Performance: Service scope (root, module, component)
MEDIUM IMPACT
This affects initial load time and runtime memory usage by controlling service instance creation and reuse.
import { Injectable } from '@angular/core'; @Injectable() export class DataService { } // Provided in component decorator providers array
import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class DataService { } // Used only in one component
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Service providedIn: 'root' | 0 (no DOM impact) | 0 | 0 | [OK] |
| Service provided in lazy module | 0 | 0 | 0 | [OK] Good |
| Service provided in component | 0 | 0 | 0 | [OK] Good |