Performance: @Injectable decorator and providedIn
MEDIUM IMPACT
This concept affects the bundle size and initial load time by controlling service tree-shaking and injection scope.
@Injectable({ providedIn: 'root' })
export class DataService {}@Injectable() export class DataService {} @NgModule({ providers: [DataService] }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Providing service in NgModule providers | 0 | 0 | 0 | [X] Bad |
| Using @Injectable({ providedIn: 'root' }) | 0 | 0 | 0 | [OK] Good |