@@ -20,9 +20,10 @@ import {Type} from '../type';
20
20
import { assertComponentType , assertDefined } from './assert' ;
21
21
import { LifecycleHooksFeature , createRootComponent , createRootComponentView , createRootContext } from './component' ;
22
22
import { getComponentDef } from './definition' ;
23
+ import { NodeInjector } from './di' ;
23
24
import { createLViewData , createNodeAtIndex , createTView , createViewNode , elementCreate , locateHostElement , refreshDescendantViews } from './instructions' ;
24
25
import { ComponentDef , RenderFlags } from './interfaces/definition' ;
25
- import { TElementNode , TNode , TNodeType , TViewNode } from './interfaces/node' ;
26
+ import { TContainerNode , TElementContainerNode , TElementNode , TNode , TNodeType , TViewNode } from './interfaces/node' ;
26
27
import { RElement , RendererFactory3 , domRendererFactory3 } from './interfaces/renderer' ;
27
28
import { FLAGS , HEADER_OFFSET , INJECTOR , LViewData , LViewFlags , RootContext , TVIEW } from './interfaces/view' ;
28
29
import { enterView , leaveView } from './state' ;
@@ -138,10 +139,12 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
138
139
ngModule && ! isInternalRootView ? ngModule . injector . get ( ROOT_CONTEXT ) : createRootContext ( ) ;
139
140
140
141
const renderer = rendererFactory . createRenderer ( hostRNode , this . componentDef ) ;
142
+ const rootViewInjector =
143
+ ngModule ? createChainedInjector ( injector , ngModule . injector ) : injector ;
141
144
// Create the root view. Uses empty TView and ContentTemplate.
142
145
const rootView : LViewData = createLViewData (
143
- renderer , createTView ( - 1 , null , 1 , 0 , null , null , null ) , rootContext , rootFlags ) ;
144
- rootView [ INJECTOR ] = ngModule ? createChainedInjector ( injector , ngModule . injector ) : injector ;
146
+ renderer , createTView ( - 1 , null , 1 , 0 , null , null , null ) , rootContext , rootFlags , undefined ,
147
+ rootViewInjector ) ;
145
148
146
149
// rootView is the parent when bootstrapping
147
150
const oldView = enterView ( rootView , null ) ;
@@ -198,8 +201,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
198
201
}
199
202
200
203
const componentRef = new ComponentRef (
201
- this . componentType , component , rootView , injector ,
202
- createElementRef ( viewEngine_ElementRef , tElementNode , rootView ) ) ;
204
+ this . componentType , component ,
205
+ createElementRef ( viewEngine_ElementRef , tElementNode , rootView ) , rootView , tElementNode ) ;
203
206
204
207
if ( isInternalRootView ) {
205
208
// The host element of the internal root view is attached to the component's host view node
@@ -232,23 +235,24 @@ export function injectComponentFactoryResolver(): viewEngine_ComponentFactoryRes
232
235
*/
233
236
export class ComponentRef < T > extends viewEngine_ComponentRef < T > {
234
237
destroyCbs : ( ( ) => void ) [ ] | null = [ ] ;
235
- injector : Injector ;
236
238
instance : T ;
237
239
hostView : ViewRef < T > ;
238
240
changeDetectorRef : ViewEngine_ChangeDetectorRef ;
239
241
componentType : Type < T > ;
240
242
241
243
constructor (
242
- componentType : Type < T > , instance : T , rootView : LViewData , injector : Injector ,
243
- public location : viewEngine_ElementRef ) {
244
+ componentType : Type < T > , instance : T , public location : viewEngine_ElementRef ,
245
+ private _rootView : LViewData ,
246
+ private _tNode : TElementNode | TContainerNode | TElementContainerNode ) {
244
247
super ( ) ;
245
248
this . instance = instance ;
246
- this . hostView = this . changeDetectorRef = new RootViewRef < T > ( rootView ) ;
247
- this . hostView . _tViewNode = createViewNode ( - 1 , rootView ) ;
248
- this . injector = injector ;
249
+ this . hostView = this . changeDetectorRef = new RootViewRef < T > ( _rootView ) ;
250
+ this . hostView . _tViewNode = createViewNode ( - 1 , _rootView ) ;
249
251
this . componentType = componentType ;
250
252
}
251
253
254
+ get injector ( ) : Injector { return new NodeInjector ( this . _tNode , this . _rootView ) ; }
255
+
252
256
destroy ( ) : void {
253
257
ngDevMode && assertDefined ( this . destroyCbs , 'NgModule already destroyed' ) ;
254
258
this . destroyCbs ! . forEach ( fn => fn ( ) ) ;
0 commit comments