* Returns the value associated to the given token from the ModuleInjector or throws exception * * @param lView The `LView` that contains the `tNode` * @param token The token to look for * @param flags Injection flags * @param notFoundValue The value to return when the injection flags is `Intern
( lView: LView, token: ProviderToken<T>, flags: InternalInjectFlags, notFoundValue?: any, )
| 406 | * @returns the value from the injector or throws an exception |
| 407 | */ |
| 408 | function lookupTokenUsingModuleInjector<T>( |
| 409 | lView: LView, |
| 410 | token: ProviderToken<T>, |
| 411 | flags: InternalInjectFlags, |
| 412 | notFoundValue?: any, |
| 413 | ): T | null { |
| 414 | if (flags & InternalInjectFlags.Optional && notFoundValue === undefined) { |
| 415 | // This must be set or the NullInjector will throw for optional deps |
| 416 | notFoundValue = null; |
| 417 | } |
| 418 | |
| 419 | if ((flags & (InternalInjectFlags.Self | InternalInjectFlags.Host)) === 0) { |
| 420 | const moduleInjector = lView[INJECTOR]; |
| 421 | // switch to `injectInjectorOnly` implementation for module injector, since module injector |
| 422 | // should not have access to Component/Directive DI scope (that may happen through |
| 423 | // `directiveInject` implementation) |
| 424 | const previousInjectImplementation = setInjectImplementation(undefined); |
| 425 | try { |
| 426 | if (moduleInjector) { |
| 427 | return (moduleInjector as BackwardsCompatibleInjector).get( |
| 428 | token, |
| 429 | notFoundValue, |
| 430 | flags & InternalInjectFlags.Optional, |
| 431 | ); |
| 432 | } else { |
| 433 | return injectRootLimpMode(token, notFoundValue, flags & InternalInjectFlags.Optional); |
| 434 | } |
| 435 | } finally { |
| 436 | setInjectImplementation(previousInjectImplementation); |
| 437 | } |
| 438 | } |
| 439 | return notFoundValueOrThrow<T>(notFoundValue, token, flags); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Returns the value associated to the given token from the NodeInjectors => ModuleInjector. |
no test coverage detected