diff --git a/packages/core/src/render3/instructions/container.ts b/packages/core/src/render3/instructions/container.ts index 0a755f3aed..dbf84f8abc 100644 --- a/packages/core/src/render3/instructions/container.ts +++ b/packages/core/src/render3/instructions/container.ts @@ -11,14 +11,14 @@ import {attachPatchData} from '../context_discovery'; import {executePreOrderHooks, registerPostOrderHooks} from '../hooks'; import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer} from '../interfaces/container'; import {ComponentTemplate} from '../interfaces/definition'; -import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType} from '../interfaces/node'; +import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType, TViewNode} from '../interfaces/node'; import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view'; import {assertNodeType} from '../node_assert'; import {appendChild, removeView} from '../node_manipulation'; import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state'; import {getNativeByTNode, load} from '../util/view_utils'; -import {addToViewTree, createDirectivesAndLocals, createLContainer, createTView, getOrCreateTNode, resolveDirectives} from './shared'; +import {addToViewTree, createDirectivesAndLocals, createLContainer, createTNode, createTView, getOrCreateTNode, resolveDirectives} from './shared'; @@ -78,6 +78,10 @@ export function ɵɵtemplate( const embeddedTView = tContainerNode.tViews = createTView( -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, tView.schemas); + const embeddedTViewNode = createTNode(tView, null, TNodeType.View, -1, null, null) as TViewNode; + embeddedTViewNode.injectorIndex = tContainerNode.injectorIndex; + embeddedTView.node = embeddedTViewNode; + if (tView.queries !== null) { tView.queries.template(tView, tContainerNode); embeddedTView.queries = tView.queries.embeddedTView(tContainerNode); diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 9f8fc6215c..8157c7730c 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -304,24 +304,6 @@ export function allocExpando(view: LView, numSlotsToAlloc: number) { //// Render ////////////////////////// -/** - * Used for creating the LView of a dynamic embedded view, either through - * ViewContainerRef.createEmbeddedView() or TemplateRef.createEmbeddedView(). - */ -export function createEmbeddedViewAndNode( - tView: TView, context: T, declarationView: LView, injectorIndex: number): LView { - const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways, null, null); - lView[DECLARATION_VIEW] = declarationView; - - assignTViewNodeToLView(tView, null, -1, lView); - - if (tView.firstTemplatePass) { - tView.node !.injectorIndex = injectorIndex; - } - - return lView; -} - /** * Processes a view in the creation mode. This includes a number of steps in a specific order: * - creating view query functions (if any); diff --git a/packages/core/src/render3/util/view_utils.ts b/packages/core/src/render3/util/view_utils.ts index 6df568037f..ddb0627ea0 100644 --- a/packages/core/src/render3/util/view_utils.ts +++ b/packages/core/src/render3/util/view_utils.ts @@ -106,11 +106,14 @@ export function getNativeByTNode(tNode: TNode, lView: LView): RNode { * @param lView */ export function getNativeByTNodeOrNull(tNode: TNode, lView: LView): RNode|null { - ngDevMode && assertTNodeForLView(tNode, lView); const index = tNode.index; - const node: RNode|null = index == -1 ? null : unwrapRNode(lView[index]); - ngDevMode && node !== null && assertDomNode(node); - return node; + if (index !== -1) { + ngDevMode && assertTNodeForLView(tNode, lView); + const node: RNode|null = unwrapRNode(lView[index]); + ngDevMode && node !== null && assertDomNode(node); + return node; + } + return null; } diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index a83f6673aa..fb9702ae6d 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -17,16 +17,15 @@ import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_Vie import {Renderer2} from '../render/api'; import {addToArray, removeFromArray} from '../util/array_utils'; import {assertDefined, assertGreaterThan, assertLessThan} from '../util/assert'; + import {assertLContainer} from './assert'; import {NodeInjector, getParentInjectorLocation} from './di'; -import {addToViewTree, createEmbeddedViewAndNode, createLContainer, renderView} from './instructions/shared'; +import {addToViewTree, createLContainer, createLView, renderView} from './instructions/shared'; import {ACTIVE_INDEX, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from './interfaces/container'; import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer'; - import {isComponent, isLContainer, isLView, isRootView} from './interfaces/type_checks'; -import {CONTEXT, DECLARATION_LCONTAINER, LView, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; - +import {CONTEXT, DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation'; import {getParentInjectorTNode} from './node_util'; @@ -108,9 +107,9 @@ export function createTemplateRef( createEmbeddedView(context: T): viewEngine_EmbeddedViewRef { const embeddedTView = this._declarationTContainer.tViews as TView; - const lView = createEmbeddedViewAndNode( - embeddedTView, context, this._declarationView, - this._declarationTContainer.injectorIndex); + const lView = createLView( + this._declarationView, embeddedTView, context, LViewFlags.CheckAlways, null, + embeddedTView.node); const declarationLContainer = this._declarationView[this._declarationTContainer.index]; ngDevMode && assertLContainer(declarationLContainer); diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index fac9ea9d8b..b2ff8da0ed 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -470,9 +470,6 @@ { "name": "assertTemplate" }, - { - "name": "assignTViewNodeToLView" - }, { "name": "attachPatchData" }, @@ -536,9 +533,6 @@ { "name": "createElementRef" }, - { - "name": "createEmbeddedViewAndNode" - }, { "name": "createLContainer" }, @@ -1478,4 +1472,4 @@ { "name": "ɵɵtextInterpolate1" } -] +] \ No newline at end of file