|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import {ENVIRONMENT_INITIALIZER} from '../../di/initializer_token'; |
9 | 10 | import {InjectionToken} from '../../di/injection_token'; |
10 | 11 | import {Injector} from '../../di/injector'; |
11 | 12 | import {getInjectorDef, InjectorType} from '../../di/interface/defs'; |
12 | 13 | import {InjectFlags, InternalInjectFlags} from '../../di/interface/injector'; |
| 14 | +import {ValueProvider} from '../../di/interface/provider'; |
| 15 | +import {INJECTOR_DEF_TYPES} from '../../di/internal_tokens'; |
13 | 16 | import {NullInjector} from '../../di/null_injector'; |
14 | 17 | import {SingleProvider, walkProviderTree} from '../../di/provider_collection'; |
15 | 18 | import {EnvironmentInjector, R3Injector} from '../../di/r3_injector'; |
16 | 19 | import {Type} from '../../interface/type'; |
17 | 20 | import {NgModuleRef as viewEngine_NgModuleRef} from '../../linker/ng_module_factory'; |
18 | 21 | import {deepForEach} from '../../util/array_utils'; |
19 | 22 | import {assertDefined, throwError} from '../../util/assert'; |
20 | | -import type {ChainedInjector} from '../component_ref'; |
21 | | -import {getComponentDef} from '../definition'; |
22 | | -import {getNodeInjectorLView, getNodeInjectorTNode, getParentInjectorLocation, NodeInjector} from '../di'; |
| 23 | +import {assertTNode, assertTNodeForLView} from '../assert'; |
| 24 | +import {ChainedInjector} from '../component_ref'; |
23 | 25 | import {getFrameworkDIDebugData} from '../debug/framework_injector_profiler'; |
24 | 26 | import {InjectedService, ProviderRecord} from '../debug/injector_profiler'; |
| 27 | +import {getComponentDef} from '../definition'; |
| 28 | +import {getNodeInjectorLView, getNodeInjectorTNode, getParentInjectorLocation, NodeInjector} from '../di'; |
25 | 29 | import {NodeInjectorOffset} from '../interfaces/injector'; |
26 | 30 | import {TContainerNode, TElementContainerNode, TElementNode, TNode} from '../interfaces/node'; |
| 31 | +import {RElement} from '../interfaces/renderer_dom'; |
27 | 32 | import {INJECTOR, LView, TVIEW} from '../interfaces/view'; |
28 | 33 |
|
29 | 34 | import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './injector_utils'; |
30 | | -import {assertTNodeForLView, assertTNode} from '../assert'; |
31 | | -import {RElement} from '../interfaces/renderer_dom'; |
32 | 35 | import {getNativeByTNode} from './view_utils'; |
33 | | -import {INJECTOR_DEF_TYPES} from '../../di/internal_tokens'; |
34 | | -import {ENVIRONMENT_INITIALIZER} from '../../di/initializer_token'; |
35 | | -import {ValueProvider} from '../../di/interface/provider'; |
36 | 36 |
|
37 | 37 | /** |
38 | 38 | * Discovers the dependencies of an injectable instance. Provides DI information about each |
@@ -585,9 +585,11 @@ function getInjectorParent(injector: Injector): Injector|null { |
585 | 585 | lView = getNodeInjectorLView(injector); |
586 | 586 | } else if (injector instanceof NullInjector) { |
587 | 587 | return null; |
| 588 | + } else if (injector instanceof ChainedInjector) { |
| 589 | + return injector.parentInjector; |
588 | 590 | } else { |
589 | 591 | throwError( |
590 | | - 'getInjectorParent only support injectors of type R3Injector, NodeInjector, NullInjector'); |
| 592 | + 'getInjectorParent only support injectors of type R3Injector, NodeInjector, NullInjector, ChainedInjector'); |
591 | 593 | } |
592 | 594 |
|
593 | 595 | const parentLocation = getParentInjectorLocation( |
@@ -633,8 +635,8 @@ function getModuleInjectorOfNodeInjector(injector: NodeInjector): Injector { |
633 | 635 | throwError('getModuleInjectorOfNodeInjector must be called with a NodeInjector'); |
634 | 636 | } |
635 | 637 |
|
636 | | - const chainedInjector = lView[INJECTOR] as ChainedInjector; |
637 | | - const moduleInjector = chainedInjector.parentInjector; |
| 638 | + const inj = lView[INJECTOR] as R3Injector | ChainedInjector; |
| 639 | + const moduleInjector = (inj instanceof ChainedInjector) ? inj.parentInjector : inj.parent; |
638 | 640 | if (!moduleInjector) { |
639 | 641 | throwError('NodeInjector must have some connection to the module injector tree'); |
640 | 642 | } |
|
0 commit comments