@@ -4,6 +4,7 @@ import * as viewModule from './view';
44import { ElementRef } from './element_ref' ;
55import { ProtoViewRef , ViewRef , internalView , internalProtoView } from './view_ref' ;
66import { ViewContainerRef } from './view_container_ref' ;
7+ import { TemplateRef } from './template_ref' ;
78import {
89 Renderer ,
910 RenderViewRef ,
@@ -39,9 +40,11 @@ export class AppViewManager {
3940 /**
4041 * Return the first child element of the host element view.
4142 */
42- // TODO(misko): remove https://github.com/angular/angular/issues/2891
4343 getHostElement ( hostViewRef : ViewRef ) : ElementRef {
4444 var hostView = internalView ( hostViewRef ) ;
45+ if ( hostView . proto . type !== ViewType . HOST ) {
46+ throw new BaseException ( 'This operation is only allowed on host views' ) ;
47+ }
4548 return hostView . elementRefs [ hostView . elementOffset ] ;
4649 }
4750
@@ -170,22 +173,42 @@ export class AppViewManager {
170173 *
171174 * See {@link AppViewManager#destroyViewInContainer}.
172175 */
173- createViewInContainer ( viewContainerLocation : ElementRef , atIndex : number ,
174- protoViewRef : ProtoViewRef , context : ElementRef = null ,
175- bindings : ResolvedBinding [ ] = null ) : ViewRef {
176+ createEmbeddedViewInContainer ( viewContainerLocation : ElementRef , atIndex : number ,
177+ templateRef : TemplateRef ) : ViewRef {
178+ var protoView = internalProtoView ( templateRef . protoViewRef ) ;
179+ if ( protoView . type !== ViewType . EMBEDDED ) {
180+ throw new BaseException ( 'This method can only be called with embedded ProtoViews!' ) ;
181+ }
182+ return this . _createViewInContainer ( viewContainerLocation , atIndex , protoView ,
183+ templateRef . elementRef , null ) ;
184+ }
185+
186+ /**
187+ *
188+ * See {@link AppViewManager#destroyViewInContainer}.
189+ */
190+ createHostViewInContainer ( viewContainerLocation : ElementRef , atIndex : number ,
191+ protoViewRef : ProtoViewRef ,
192+ imperativelyCreatedInjector : ResolvedBinding [ ] ) : ViewRef {
176193 var protoView = internalProtoView ( protoViewRef ) ;
177- var parentView = internalView ( viewContainerLocation . parentView ) ;
178- var boundElementIndex = viewContainerLocation . boundElementIndex ;
179- var contextView = null ;
180- var contextBoundElementIndex = null ;
181- if ( isPresent ( context ) ) {
182- contextView = internalView ( context . parentView ) ;
183- contextBoundElementIndex = context . boundElementIndex ;
184- } else {
185- contextView = parentView ;
186- contextBoundElementIndex = boundElementIndex ;
194+ if ( protoView . type !== ViewType . HOST ) {
195+ throw new BaseException ( 'This method can only be called with host ProtoViews!' ) ;
187196 }
197+ return this . _createViewInContainer ( viewContainerLocation , atIndex , protoView ,
198+ viewContainerLocation , imperativelyCreatedInjector ) ;
199+ }
188200
201+ /**
202+ *
203+ * See {@link AppViewManager#destroyViewInContainer}.
204+ */
205+ _createViewInContainer ( viewContainerLocation : ElementRef , atIndex : number ,
206+ protoView : viewModule . AppProtoView , context : ElementRef ,
207+ imperativelyCreatedInjector : ResolvedBinding [ ] ) : ViewRef {
208+ var parentView = internalView ( viewContainerLocation . parentView ) ;
209+ var boundElementIndex = viewContainerLocation . boundElementIndex ;
210+ var contextView = internalView ( context . parentView ) ;
211+ var contextBoundElementIndex = context . boundElementIndex ;
189212 var embeddedFragmentView = contextView . getNestedView ( contextBoundElementIndex ) ;
190213 var view ;
191214 if ( protoView . type === ViewType . EMBEDDED && isPresent ( embeddedFragmentView ) &&
@@ -194,7 +217,8 @@ export class AppViewManager {
194217 view = embeddedFragmentView ;
195218 this . _attachRenderView ( parentView , boundElementIndex , atIndex , view ) ;
196219 } else {
197- // Case 2: instantiate another copy of the template. This is a separate case
220+ // Case 2: instantiate another copy of the template or a host ProtoView.
221+ // This is a separate case
198222 // as we only inline one copy of the template into the parent view.
199223 view = this . _createPooledView ( protoView ) ;
200224 this . _attachRenderView ( parentView , boundElementIndex , atIndex , view ) ;
@@ -203,7 +227,8 @@ export class AppViewManager {
203227 this . _utils . attachViewInContainer ( parentView , boundElementIndex , contextView ,
204228 contextBoundElementIndex , atIndex , view ) ;
205229 this . _utils . hydrateViewInContainer ( parentView , boundElementIndex , contextView ,
206- contextBoundElementIndex , atIndex , bindings ) ;
230+ contextBoundElementIndex , atIndex ,
231+ imperativelyCreatedInjector ) ;
207232 return view . ref ;
208233 }
209234
0 commit comments