@@ -24,6 +24,7 @@ import {
2424 OutputRef ,
2525 reflectComponentType ,
2626 createComponent ,
27+ ComponentMirror ,
2728} from '@angular/core' ;
2829import { merge , Observable , ReplaySubject } from 'rxjs' ;
2930import { switchMap } from 'rxjs/operators' ;
@@ -40,18 +41,17 @@ import {
4041const DESTROY_DELAY = 10 ;
4142
4243/**
43- * Factory that creates new ComponentNgElementStrategy instance. Uses reflectComponentType
44- * to obtain component metadata and passes the component type to each strategy.
44+ * Factory that creates new ComponentNgElementStrategy instance. Gets the component factory with the
45+ * constructor's injector's factory resolver and passes that factory to each strategy.
4546 */
4647export class ComponentNgElementStrategyFactory implements NgElementStrategyFactory {
47- component : Type < any > ;
48+ componentMirror : ComponentMirror < any > ;
4849
4950 inputMap = new Map < string , string > ( ) ;
5051
51- constructor ( component : Type < any > , injector : Injector ) {
52- this . component = component ;
53- const mirror = reflectComponentType ( component ) ;
54- for ( const input of mirror . inputs ) {
52+ constructor ( protected component : Type < any > ) {
53+ this . componentMirror = reflectComponentType ( component ) ! ;
54+ for ( const input of this . componentMirror . inputs ) {
5555 this . inputMap . set ( input . propName , input . templateName ) ;
5656 }
5757 }
@@ -200,10 +200,10 @@ export class ComponentNgElementStrategy implements NgElementStrategy {
200200 const childInjector = Injector . create ( { providers : [ ] , parent : this . injector } ) ;
201201 const projectableNodes = extractProjectableNodes (
202202 element ,
203- reflectComponentType ( this . component ) . ngContentSelectors as string [ ] ,
203+ reflectComponentType ( this . component ) ! . ngContentSelectors as string [ ] ,
204204 ) ;
205205 this . componentRef = createComponent ( this . component , {
206- environmentInjector : this . injector . get ( EnvironmentInjector ) ,
206+ environmentInjector : this . injector as EnvironmentInjector ,
207207 elementInjector : childInjector ,
208208 hostElement : element ,
209209 projectableNodes,
@@ -227,15 +227,15 @@ export class ComponentNgElementStrategy implements NgElementStrategy {
227227
228228 /** Sets up listeners for the component's outputs so that the events stream emits the events. */
229229 protected initializeOutputs ( componentRef : ComponentRef < any > ) : void {
230- const eventEmitters : Observable < NgElementStrategyEvent > [ ] = reflectComponentType ( this . component ) . outputs . map (
231- ( { propName , templateName } ) => {
232- const emitter : EventEmitter < any > | OutputRef < any > = componentRef . instance [ propName ] ;
233- return new Observable ( ( observer ) => {
234- const sub = emitter . subscribe ( ( value ) => observer . next ( { name : templateName , value } ) ) ;
235- return ( ) => sub . unsubscribe ( ) ;
236- } ) ;
237- } ,
238- ) ;
230+ const eventEmitters : Observable < NgElementStrategyEvent > [ ] = reflectComponentType (
231+ this . component ,
232+ ) ! . outputs . map ( ( { propName , templateName } ) => {
233+ const emitter : EventEmitter < any > | OutputRef < any > = componentRef . instance [ propName ] ;
234+ return new Observable ( ( observer ) => {
235+ const sub = emitter . subscribe ( ( value ) => observer . next ( { name : templateName , value } ) ) ;
236+ return ( ) => sub . unsubscribe ( ) ;
237+ } ) ;
238+ } ) ;
239239
240240 this . eventEmitters . next ( eventEmitters ) ;
241241 }
0 commit comments