@@ -4,45 +4,31 @@ import {Injector} from 'angular2/di';
44import * as eiModule from 'angular2/src/core/compiler/element_injector' ;
55import { isPresent , isBlank } from 'angular2/src/facade/lang' ;
66
7- import * as renderApi from 'angular2/src/render/api' ;
87import * as viewModule from './view' ;
9- import * as vfModule from './view_factory' ;
10- import * as vhModule from './view_hydrator' ;
11- import { Renderer } from 'angular2/src/render/api' ;
8+ import { ViewContainerRef } from 'angular2/src/render/api' ;
129
1310/**
1411 * @exportedAs angular2/view
1512 */
1613export class ViewContainer {
17- viewFactory : vfModule . ViewFactory ;
18- viewHydrator: vhModule . AppViewHydrator ;
19- renderer: Renderer ;
20-
21- render:renderApi . ViewContainerRef ;
2214 parentView : viewModule . AppView ;
2315 defaultProtoView: viewModule . AppProtoView ;
2416 _views: List < viewModule . AppView > ;
2517 elementInjector: eiModule . ElementInjector ;
26- appInjector: Injector ;
27- hostElementInjector: eiModule . ElementInjector ;
2818
29- constructor ( viewFactory :vfModule . ViewFactory ,
30- renderer : Renderer ,
31- parentView : viewModule . AppView ,
19+ constructor ( parentView : viewModule . AppView ,
3220 defaultProtoView : viewModule . AppProtoView ,
3321 elementInjector : eiModule . ElementInjector ) {
34- this . viewFactory = viewFactory ;
35- this . viewHydrator = null ;
36- this . renderer = renderer ;
37- this . render = null ;
3822 this . parentView = parentView ;
3923 this . defaultProtoView = defaultProtoView ;
4024 this . elementInjector = elementInjector ;
4125
4226 // The order in this list matches the DOM order.
4327 this . _views = [ ] ;
44- this . appInjector = null ;
45- this . hostElementInjector = null ;
28+ }
29+
30+ getRender ( ) {
31+ return new ViewContainerRef ( this . parentView . render , this . elementInjector . getBoundElementIndex ( ) ) ;
4632 }
4733
4834 internalClearWithoutRender ( ) {
@@ -71,22 +57,22 @@ export class ViewContainer {
7157 }
7258
7359 hydrated ( ) {
74- return isPresent ( this . appInjector ) ;
60+ return this . parentView . hydrated ( ) ;
7561 }
7662
7763 // TODO(rado): profile and decide whether bounds checks should be added
7864 // to the methods below.
79- create ( atIndex = - 1 , protoView :viewModule . AppProtoView = null ) : viewModule . AppView {
65+ create ( atIndex = - 1 , protoView :viewModule . AppProtoView = null , injector : Injector = null ) : viewModule . AppView {
8066 if ( atIndex == - 1 ) atIndex = this . _views . length ;
8167 if ( ! this . hydrated ( ) ) throw new BaseException (
8268 'Cannot create views on a dehydrated ViewContainer' ) ;
8369 if ( isBlank ( protoView ) ) {
8470 protoView = this . defaultProtoView ;
8571 }
86- var newView = this . viewFactory . getView ( protoView ) ;
72+ var newView = this . parentView . viewFactory . getView ( protoView ) ;
8773 // insertion must come before hydration so that element injector trees are attached.
8874 this . _insertInjectors ( newView , atIndex ) ;
89- this . viewHydrator . hydrateViewInViewContainer ( this , atIndex , newView ) ;
75+ this . parentView . viewHydrator . hydrateViewInViewContainer ( this , atIndex , newView , injector ) ;
9076
9177 return newView ;
9278 }
@@ -95,7 +81,7 @@ export class ViewContainer {
9581 if ( atIndex == - 1 ) atIndex = this . _views . length ;
9682 this . _insertInjectors ( view , atIndex ) ;
9783 this . parentView . changeDetector . addChild ( view . changeDetector ) ;
98- this . renderer . insertViewIntoContainer ( this . render , atIndex , view . render ) ;
84+ this . parentView . renderer . insertViewIntoContainer ( this . getRender ( ) , atIndex , view . render ) ;
9985 return view ;
10086 }
10187
@@ -110,9 +96,9 @@ export class ViewContainer {
11096 if ( atIndex == - 1 ) atIndex = this . _views . length - 1 ;
11197 var view = this . _views [ atIndex ] ;
11298 // opposite order as in create
113- this . viewHydrator . dehydrateViewInViewContainer ( this , atIndex , view ) ;
99+ this . parentView . viewHydrator . dehydrateViewInViewContainer ( this , atIndex , view ) ;
114100 this . _detachInjectors ( atIndex ) ;
115- this . viewFactory . returnView ( view ) ;
101+ this . parentView . viewFactory . returnView ( view ) ;
116102 // view is intentionally not returned to the client.
117103 }
118104
@@ -124,7 +110,7 @@ export class ViewContainer {
124110 if ( atIndex == - 1 ) atIndex = this . _views . length - 1 ;
125111 var detachedView = this . _detachInjectors ( atIndex ) ;
126112 detachedView . changeDetector . remove ( ) ;
127- this . renderer . detachViewFromContainer ( this . render , atIndex ) ;
113+ this . parentView . renderer . detachViewFromContainer ( this . getRender ( ) , atIndex ) ;
128114 return detachedView ;
129115 }
130116
0 commit comments