Angular 9 References/ Core
References

@Injectable

This is the documentation for Angular 9.
You can switch to the latest version Angular 10.

The @Injectable decorator identifies services and other classes that are intended to be injected. It can also be used to configure a provider for those services.

Example

import { Injectable } from '@angular/core';

@Injectable()
export class MyService {
  constructor() { }
}

Options

providedIn#

providedIn?: Type<any>|'root'|'platform'|'any'|null
Tells Angular that the root injector is responsible for creating an instance of the service (by invoking its constructor) and making it available across the application.Sometimes it's not desirable to have a service always be provided in the application root injector. Perhaps users should explicitly opt-in to using the service, or the service should be provided in a lazily-loaded context. In this case, the provider should be associated with a specific `@NgModule` class, and will be used by whichever injector includes that module.