Angular › Dependency Injection Providers & Injection Tokens
What is a provider in Angular's dependency injection system?
BeginnerAnswer
A provider tells Angular's dependency injection system how to create a specific value or service when something asks for it. Most commonly this is just the class itself, but a provider can also describe using a different class, a fixed value, or a factory function instead.
@Injectable({ providedIn: 'root' })
export class LoggerService {
log(message: string) { console.log(message); }
}
// The providedIn root option registers this as a provider automatically at the app levelReal-world example A logging service is registered once as a provider at the root of the app, letting any component or service throughout the entire app request and receive the exact same shared instance automatically.