Performance: Service-to-service injection
MEDIUM IMPACT
This affects the initial load time and runtime responsiveness by controlling how services are created and shared in Angular apps.
import { Injectable, inject } from '@angular/core'; import { HeavyService } from './heavy.service'; @Injectable({ providedIn: 'root' }) export class UserService { private heavyService = inject(HeavyService); getUser() { return this.heavyService.fetchData(); } }
import { Injectable } from '@angular/core'; import { HeavyService } from './heavy.service'; @Injectable({ providedIn: 'root' }) export class UserService { constructor(private heavyService: HeavyService) {} getUser() { return this.heavyService.fetchData(); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager service injection | 0 (no DOM impact) | 0 | 0 | [!] OK |
| Lazy service injection with inject() | 0 (no DOM impact) | 0 | 0 | [OK] Good |