From 7d89cff54544ffafdf370e9db6036fa0918c45c9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 28 Nov 2018 20:42:40 -0800 Subject: [PATCH] fix(ivy): Ensure ComponentFactory uses both injectors to retrieve rendererFactory (#27341) PR Close #27341 --- packages/core/src/render3/component_ref.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index 8b1cd04fd7..b89bae4bb8 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -115,15 +115,12 @@ export class ComponentFactory extends viewEngine_ComponentFactory { ngModule?: viewEngine_NgModuleRef|undefined): viewEngine_ComponentRef { const isInternalRootView = rootSelectorOrNode === undefined; - let rendererFactory: RendererFactory3; - let sanitizer: Sanitizer|null = null; + const rootViewInjector = + ngModule ? createChainedInjector(injector, ngModule.injector) : injector; - if (ngModule) { - rendererFactory = ngModule.injector.get(RendererFactory2) as RendererFactory3; - sanitizer = ngModule.injector.get(Sanitizer, null); - } else { - rendererFactory = domRendererFactory3; - } + const rendererFactory = + rootViewInjector.get(RendererFactory2, domRendererFactory3) as RendererFactory3; + const sanitizer = rootViewInjector.get(Sanitizer, null); const hostRNode = isInternalRootView ? elementCreate(this.selector, rendererFactory.createRenderer(null, this.componentDef)) : @@ -132,11 +129,9 @@ export class ComponentFactory extends viewEngine_ComponentFactory { const rootFlags = this.componentDef.onPush ? LViewFlags.Dirty | LViewFlags.IsRoot : LViewFlags.CheckAlways | LViewFlags.IsRoot; const rootContext: RootContext = - ngModule && !isInternalRootView ? ngModule.injector.get(ROOT_CONTEXT) : createRootContext(); + !isInternalRootView ? rootViewInjector.get(ROOT_CONTEXT) : createRootContext(); const renderer = rendererFactory.createRenderer(hostRNode, this.componentDef); - const rootViewInjector = - ngModule ? createChainedInjector(injector, ngModule.injector) : injector; if (rootSelectorOrNode && hostRNode) { ngDevMode && ngDevMode.rendererSetAttribute++;