( lView: LView, tView: TView, index: number, tNode: TDirectiveHostNode, flags?: InternalInjectFlags, )
| 734 | * instantiates the `injectable` and caches the value. |
| 735 | */ |
| 736 | export function getNodeInjectable( |
| 737 | lView: LView, |
| 738 | tView: TView, |
| 739 | index: number, |
| 740 | tNode: TDirectiveHostNode, |
| 741 | flags?: InternalInjectFlags, |
| 742 | ): any { |
| 743 | let value = lView[index]; |
| 744 | const tData = tView.data; |
| 745 | if (value instanceof NodeInjectorFactory) { |
| 746 | const factory: NodeInjectorFactory = value; |
| 747 | ngDevMode && injectionPath.push(factory.name ?? 'unknown'); |
| 748 | if (factory.resolving) { |
| 749 | let token = ''; |
| 750 | if (ngDevMode) { |
| 751 | token = stringifyForError(tData[index]); |
| 752 | throw cyclicDependencyErrorWithDetails(token, injectionPath); |
| 753 | } else { |
| 754 | throw cyclicDependencyError(token); |
| 755 | } |
| 756 | } |
| 757 | const previousIncludeViewProviders = setIncludeViewProviders(factory.canSeeViewProviders); |
| 758 | factory.resolving = true; |
| 759 | |
| 760 | // tData indexes mirror the concrete instances in its corresponding LView. |
| 761 | // lView[index] here is either the injectable instance itself or a factory, |
| 762 | // therefore tData[index] is the constructor of that injectable or a |
| 763 | // definition object that contains the constructor in a `.type` field. |
| 764 | const token = |
| 765 | (tData[index] as DirectiveDef<unknown> | ComponentDef<unknown>).type || tData[index]; |
| 766 | |
| 767 | let prevInjectContext: InjectorProfilerContext | undefined; |
| 768 | if (ngDevMode) { |
| 769 | const injector = new NodeInjector(tNode, lView); |
| 770 | prevInjectContext = setInjectorProfilerContext({injector, token}); |
| 771 | } |
| 772 | |
| 773 | const previousInjectImplementation = factory.injectImpl |
| 774 | ? setInjectImplementation(factory.injectImpl) |
| 775 | : null; |
| 776 | const success = enterDI(lView, tNode, InternalInjectFlags.Default); |
| 777 | ngDevMode && |
| 778 | assertEqual( |
| 779 | success, |
| 780 | true, |
| 781 | "Because flags do not contain `SkipSelf' we expect this to always succeed.", |
| 782 | ); |
| 783 | // Constructors and field initializers must not run in a reactive context, otherwise their |
| 784 | // signal reads become dependencies of the caller and their signal writes are rejected. |
| 785 | // `R3Injector.hydrate` does the same for the environment injector. |
| 786 | const prevConsumer = setActiveConsumer(null); |
| 787 | try { |
| 788 | ngDevMode && emitInjectorToCreateInstanceEvent(token); |
| 789 | |
| 790 | value = lView[index] = factory.factory(undefined, flags, tData, lView, tNode); |
| 791 | |
| 792 | ngDevMode && emitInstanceCreatedByInjectorEvent(value); |
| 793 |
no test coverage detected