( token: ProviderToken<T>, flags = InternalInjectFlags.Default, )
| 91 | flags?: InternalInjectFlags, |
| 92 | ): T | null; |
| 93 | export function injectInjectorOnly<T>( |
| 94 | token: ProviderToken<T>, |
| 95 | flags = InternalInjectFlags.Default, |
| 96 | ): T | null { |
| 97 | const currentInjector = getCurrentInjector(); |
| 98 | if (currentInjector === undefined) { |
| 99 | throw new RuntimeError( |
| 100 | RuntimeErrorCode.MISSING_INJECTION_CONTEXT, |
| 101 | ngDevMode && |
| 102 | `The \`${stringify(token)}\` token injection failed. \`inject()\` function must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with \`runInInjectionContext\`.`, |
| 103 | ); |
| 104 | } else if (currentInjector === null) { |
| 105 | return injectRootLimpMode(token, undefined, flags); |
| 106 | } else { |
| 107 | const options = convertToInjectOptions(flags); |
| 108 | // TODO: improve the typings here. |
| 109 | // `token` can be a multi: true provider definition, which is considered as a Token but not represented in the typings |
| 110 | const value = currentInjector.retrieve(token as PrimitivesInjectionToken<T>, options) as T; |
| 111 | ngDevMode && emitInjectEvent(token as Type<unknown>, value, flags); |
| 112 | if (isNotFound(value)) { |
| 113 | if (options.optional) { |
| 114 | return null; |
| 115 | } |
| 116 | throw value; |
| 117 | } |
| 118 | return value; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Generated instruction: injects a token from the currently active injector. |
nothing calls this directly
no test coverage detected
searching dependent graphs…