diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 4852d490c1..d25c001790 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -1096,14 +1096,27 @@ function instantiateAllDirectives(tView: TView, lView: LView, tNode: TDirectiveH if (!tView.firstTemplatePass) { getOrCreateNodeInjectorForNode(tNode, lView); } + for (let i = start; i < end; i++) { const def = tView.data[i] as DirectiveDef; - if (isComponentDef(def)) { - assertNodeOfPossibleTypes(tNode, TNodeType.Element); - addComponentLogic(lView, tNode as TElementNode, def); + const isComponent = isComponentDef(def); + + if (isComponent) { + ngDevMode && assertNodeOfPossibleTypes(tNode, TNodeType.Element); + addComponentLogic(lView, tNode as TElementNode, def as ComponentDef); } + const directive = getNodeInjectable(tView.data, lView, i, tNode); - postProcessDirective(lView, tNode, directive, def, i - start); + + postProcessBaseDirective(lView, tNode, directive); + if (tNode.initialInputs !== null) { + setInputsFromAttrs(lView, i - start, directive, def, tNode); + } + + if (isComponent) { + const componentView = getComponentLViewByIndex(tNode.index, lView); + componentView[CONTEXT] = directive; + } } } @@ -1169,23 +1182,6 @@ export function generateExpandoInstructionBlock( ])).push(elementIndex, providerCount, directiveCount); } -/** - * Process a directive on the current node after its creation. - */ -function postProcessDirective( - lView: LView, hostTNode: TNode, directive: T, def: DirectiveDef, - directiveDefIdx: number): void { - postProcessBaseDirective(lView, hostTNode, directive); - if (hostTNode.initialInputs !== null) { - setInputsFromAttrs(lView, directiveDefIdx, directive, def, hostTNode); - } - - if (isComponentDef(def)) { - const componentView = getComponentLViewByIndex(hostTNode.index, lView); - componentView[CONTEXT] = directive; - } -} - /** * A lighter version of postProcessDirective() that is used for the root component. */