Providers
Provider Types
Section titled “Provider Types”{ provide: AuthService, useClass: MockAuthService } // useClass{ provide: API_URL, useValue: 'https://api.example.com' } // useValue{ provide: LogLevel, useFactory: () => production ? 'error' : 'debug' } // useFactory{ provide: NewService, useExisting: LegacyService } // useExistingRegistration Methods
Section titled “Registration Methods”- @Injectable({ providedIn: ‘root’ }) — Tree-shakeable singleton
- Component providers — New instance per component
- Module providers — Shared within module
Summary
Section titled “Summary”Choose the provider type and registration method based on your use case.”