@@ -23,14 +23,16 @@ export function createRenderView(fragmentCmds: RenderTemplateCmd[], inplaceEleme
2323 fragments . push ( new DefaultRenderFragmentRef ( context . fragments [ i ] ) ) ;
2424 }
2525 view = new DefaultRenderView < any > ( fragments , context . boundTextNodes , context . boundElements ,
26- context . nativeShadowRoots , context . globalEventAdders ) ;
26+ context . nativeShadowRoots , context . globalEventAdders ,
27+ context . rootContentInsertionPoints ) ;
2728 return view ;
2829}
2930
3031export interface NodeFactory < N > {
3132 resolveComponentTemplate ( templateId : number ) : RenderTemplateCmd [ ] ;
3233 createTemplateAnchor ( attrNameAndValues : string [ ] ) : N ;
3334 createElement ( name : string , attrNameAndValues : string [ ] ) : N ;
35+ createRootContentInsertionPoint ( ) : N ;
3436 mergeElement ( existing : N , attrNameAndValues : string [ ] ) ;
3537 createShadowRoot ( host : N , templateId : number ) : N ;
3638 createText ( value : string ) : N ;
@@ -41,14 +43,19 @@ export interface NodeFactory<N> {
4143
4244class BuildContext < N > {
4345 constructor ( private _eventDispatcher : Function , public factory : NodeFactory < N > ,
44- private _inplaceElement : N ) { }
46+ private _inplaceElement : N ) {
47+ this . isHost = isPresent ( ( _inplaceElement ) ) ;
48+ }
4549 private _builders : RenderViewBuilder < N > [ ] = [ ] ;
4650
4751 globalEventAdders : Function [ ] = [ ] ;
4852 boundElements : N [ ] = [ ] ;
4953 boundTextNodes : N [ ] = [ ] ;
5054 nativeShadowRoots : N [ ] = [ ] ;
5155 fragments : N [ ] [ ] = [ ] ;
56+ rootContentInsertionPoints : N [ ] = [ ] ;
57+ componentCount : number = 0 ;
58+ isHost : boolean ;
5259
5360 build ( fragmentCmds : RenderTemplateCmd [ ] ) {
5461 this . enqueueFragmentBuilder ( null , fragmentCmds ) ;
@@ -65,6 +72,7 @@ class BuildContext<N> {
6572 }
6673
6774 enqueueComponentBuilder ( component : Component < N > ) {
75+ this . componentCount ++ ;
6876 this . _builders . push ( new RenderViewBuilder < N > (
6977 component , null , this . factory . resolveComponentTemplate ( component . cmd . templateId ) ) ) ;
7078 }
@@ -131,10 +139,20 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
131139 }
132140 visitNgContent ( cmd : RenderNgContentCmd , context : BuildContext < N > ) : any {
133141 if ( isPresent ( this . parentComponent ) ) {
134- var projectedNodes = this . parentComponent . project ( cmd . index ) ;
135- for ( var i = 0 ; i < projectedNodes . length ; i ++ ) {
136- var node = projectedNodes [ i ] ;
137- this . _addChild ( node , cmd . ngContentIndex , context ) ;
142+ if ( this . parentComponent . isRoot ) {
143+ var insertionPoint = context . factory . createRootContentInsertionPoint ( ) ;
144+ if ( this . parent instanceof Component ) {
145+ context . factory . appendChild ( ( < Component < N > > this . parent ) . shadowRoot , insertionPoint ) ;
146+ } else {
147+ context . factory . appendChild ( < N > this . parent , insertionPoint ) ;
148+ }
149+ context . rootContentInsertionPoints . push ( insertionPoint ) ;
150+ } else {
151+ var projectedNodes = this . parentComponent . project ( cmd . index ) ;
152+ for ( var i = 0 ; i < projectedNodes . length ; i ++ ) {
153+ var node = projectedNodes [ i ] ;
154+ this . _addChild ( node , cmd . ngContentIndex , context ) ;
155+ }
138156 }
139157 }
140158 return null ;
@@ -154,7 +172,8 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
154172 root = context . factory . createShadowRoot ( el , cmd . templateId ) ;
155173 context . nativeShadowRoots . push ( root ) ;
156174 }
157- var component = new Component ( el , root , cmd ) ;
175+ var isRoot = context . componentCount === 0 && context . isHost ;
176+ var component = new Component ( el , root , cmd , isRoot ) ;
158177 context . enqueueComponentBuilder ( component ) ;
159178 this . parentStack . push ( component ) ;
160179 return null ;
@@ -213,7 +232,8 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
213232class Component < N > {
214233 private contentNodesByNgContentIndex : N [ ] [ ] = [ ] ;
215234
216- constructor ( public hostElement : N , public shadowRoot : N , public cmd : RenderBeginComponentCmd ) { }
235+ constructor ( public hostElement : N , public shadowRoot : N , public cmd : RenderBeginComponentCmd ,
236+ public isRoot : boolean ) { }
217237 addContentNode ( ngContentIndex : number , node : N , context : BuildContext < N > ) {
218238 if ( isBlank ( ngContentIndex ) ) {
219239 if ( this . cmd . nativeShadow ) {
0 commit comments