diff --git a/packages/core/src/render3/instructions/container.ts b/packages/core/src/render3/instructions/container.ts index c3869b2698..2987d0dd3d 100644 --- a/packages/core/src/render3/instructions/container.ts +++ b/packages/core/src/render3/instructions/container.ts @@ -75,7 +75,7 @@ export function ɵɵtemplate( -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null); } - createDirectivesAndLocals(tView, lView, localRefs, localRefExtractor); + createDirectivesAndLocals(tView, lView, tContainerNode, localRefs, localRefExtractor); addTContainerToQueries(lView, tContainerNode); attachPatchData(getNativeByTNode(tContainerNode, lView), lView); registerPostOrderHooks(tView, tContainerNode); diff --git a/packages/core/src/render3/instructions/element.ts b/packages/core/src/render3/instructions/element.ts index ff45081263..21736e7d3a 100644 --- a/packages/core/src/render3/instructions/element.ts +++ b/packages/core/src/render3/instructions/element.ts @@ -85,7 +85,7 @@ export function ɵɵelementStart( } appendChild(native, tNode, lView); - createDirectivesAndLocals(tView, lView, localRefs); + createDirectivesAndLocals(tView, lView, tNode, localRefs); // any immediate children of a component or template container must be pre-emptively // monkey-patched with the component view data so that the element can be inspected diff --git a/packages/core/src/render3/instructions/element_container.ts b/packages/core/src/render3/instructions/element_container.ts index d2e9af7486..47f08c8763 100644 --- a/packages/core/src/render3/instructions/element_container.ts +++ b/packages/core/src/render3/instructions/element_container.ts @@ -59,7 +59,7 @@ export function ɵɵelementContainerStart( } appendChild(native, tNode, lView); - createDirectivesAndLocals(tView, lView, localRefs); + createDirectivesAndLocals(tView, lView, tNode, localRefs); attachPatchData(native, lView); const currentQueries = lView[QUERIES]; diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index df3264dd62..021a0ca8a3 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -528,19 +528,18 @@ export function executeContentQueries(tView: TView, tNode: TNode, lView: LView) * @param localRefExtractor mapping function that extracts local ref value from TNode */ export function createDirectivesAndLocals( - tView: TView, lView: LView, localRefs: string[] | null | undefined, + tView: TView, lView: LView, tNode: TElementNode | TContainerNode | TElementContainerNode, + localRefs: string[] | null | undefined, localRefExtractor: LocalRefExtractor = getNativeByTNode) { if (!getBindingsEnabled()) return; - const previousOrParentTNode = getPreviousOrParentTNode(); if (tView.firstTemplatePass) { ngDevMode && ngDevMode.firstTemplatePass++; resolveDirectives( - tView, lView, findDirectiveMatches(tView, lView, previousOrParentTNode), - previousOrParentTNode, localRefs || null); + tView, lView, findDirectiveMatches(tView, lView, tNode), tNode, localRefs || null); } - instantiateAllDirectives(tView, lView, previousOrParentTNode); - invokeDirectivesHostBindings(tView, lView, previousOrParentTNode); - saveResolvedLocalsInData(lView, previousOrParentTNode, localRefExtractor); + instantiateAllDirectives(tView, lView, tNode); + invokeDirectivesHostBindings(tView, lView, tNode); + saveResolvedLocalsInData(lView, tNode, localRefExtractor); setActiveHostElement(null); } @@ -1194,8 +1193,9 @@ function postProcessBaseDirective( * Matches the current node against all available selectors. * If a component is matched (at most one), it is returned in first position in the array. */ -function findDirectiveMatches(tView: TView, viewData: LView, tNode: TNode): DirectiveDef[]| - null { +function findDirectiveMatches( + tView: TView, viewData: LView, + tNode: TElementNode | TContainerNode | TElementContainerNode): DirectiveDef[]|null { ngDevMode && assertEqual(tView.firstTemplatePass, true, 'should run on first template pass only'); const registry = tView.directiveRegistry; let matches: any[]|null = null; @@ -1204,11 +1204,7 @@ function findDirectiveMatches(tView: TView, viewData: LView, tNode: TNode): Dire const def = registry[i] as ComponentDef| DirectiveDef; if (isNodeMatchingSelectorList(tNode, def.selectors !, /* isProjectionMode */ false)) { matches || (matches = ngDevMode ? new MatchesArray !() : []); - diPublicInInjector( - getOrCreateNodeInjectorForNode( - getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode, - viewData), - tView, def.type); + diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, viewData), tView, def.type); if (isComponentDef(def)) { if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);