@ -70,18 +70,24 @@ export function injectInjectorOnly<T>(
|
||||
|
||||
/**
|
||||
* Injects a token from the currently active injector.
|
||||
* Must be used in the context of a factory function such as one defined for an
|
||||
* `InjectionToken`. Throws an error if not called from such a context.
|
||||
*
|
||||
* This function must be used in the context of a factory function such as one defined for an
|
||||
* `InjectionToken`, and will throw an error if not called from such a context.
|
||||
* Within such a factory function, using this function to request injection of a dependency
|
||||
* is faster and more type-safe than providing an additional array of dependencies
|
||||
* (as has been common with `useFactory` providers).
|
||||
*
|
||||
* @param token The injection token for the dependency to be injected.
|
||||
* @param flags Optional flags that control how injection is executed.
|
||||
* The flags correspond to injection strategies that can be specified with
|
||||
* parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
|
||||
* @returns True if injection is successful, null otherwise.
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* ### Example
|
||||
*
|
||||
* {@example core/di/ts/injector_spec.ts region='ShakeableInjectionToken'}
|
||||
*
|
||||
* Within such a factory function `inject` is utilized to request injection of a dependency, instead
|
||||
* of providing an additional array of dependencies as was common to do with `useFactory` providers.
|
||||
* `inject` is faster and more type-safe.
|
||||
* {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
|
Reference in New Issue
Block a user