inject
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@Injectableor@Component. - In the initializer for fields of such classes.
- In the factory function specified for
useFactoryof aProvideror an@Injectable. - In the
factoryfunction specified for anInjectionToken. - In a stackframe of a function call in a DI context
function inject<T>(token: ProviderToken<T>): T;
Tfunction inject<T>(token: ProviderToken<T>, flags?: InjectFlags | undefined): T | null;
InjectFlags | undefinedControl how injection is executed. The flags correspond to injection strategies that
can be specified with parameter decorators @Host, @Self, @SkipSelf, and @Optional.
T | nullfunction inject<T>(token: ProviderToken<T>, options: InjectOptions & { optional?: false | undefined; }): T;
InjectOptions & { optional?: false | undefined; }Control how injection is executed. Options correspond to injection strategies
that can be specified with parameter decorators @Host, @Self, @SkipSelf, and
@Optional.
Tfunction inject<T>(token: ProviderToken<T>, options: InjectOptions): T | null;
InjectOptionsControl how injection is executed. Options correspond to injection strategies
that can be specified with parameter decorators @Host, @Self, @SkipSelf, and
@Optional.
T | nullfunction inject(token: HostAttributeToken): string;
HostAttributeTokenA token that represents a static attribute on the host node that should be injected.
stringfunction inject(token: HostAttributeToken, options: { optional: true; }): string | null;
HostAttributeTokenA token that represents a static attribute on the host node that should be injected.
{ optional: true; }string | nullfunction inject(token: HostAttributeToken, options: { optional: false; }): string;
HostAttributeTokenA token that represents a static attribute on the host node that should be injected.
{ optional: false; }string
