• Overview
@angular/core

inject

function
stable

Injects a token from the currently active injector. inject is only supported in an injection context. It can be used during:

  • Construction (via the constructor) of a class being instantiated by the DI system, such as an @Injectable or @Component.
  • In the initializer for fields of such classes.
  • In the factory function specified for useFactory of a Provider or an @Injectable.
  • In the factory function specified for an InjectionToken.
  • In a stackframe of a function call in a DI context

API

function inject<T>(token: ProviderToken<T>): T;function inject<T>(  token: ProviderToken<T>,  options: