1- import { ApplicationRef , ComponentFactory , ComponentRef , DestroyRef , EventEmitter , Injector , QueryList , Type , ViewContainerRef , reflectComponentType } from '@angular/core' ;
1+ import { ApplicationRef , ComponentRef , createComponent , DestroyRef , EnvironmentInjector , EventEmitter , Injector , QueryList , Type , ViewContainerRef , reflectComponentType } from '@angular/core' ;
22import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
33import { NgElement , NgElementStrategyEvent } from '@angular/elements' ;
44import { fromEvent , Observable } from 'rxjs' ;
@@ -62,12 +62,12 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
6262 }
6363
6464 constructor (
65- private _componentFactory : ComponentFactory < any > ,
65+ private _component : Type < any > ,
6666 private _injector : Injector ,
6767 private _inputMap : Map < string , string > ,
6868 private config : ComponentConfig [ ] ,
6969 ) {
70- super ( _componentFactory , _injector , _inputMap ) ;
70+ super ( _component , _injector , _inputMap ) ;
7171 }
7272
7373 protected override async initializeComponent ( element : HTMLElement ) {
@@ -82,16 +82,17 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
8282 // set componentRef to non-null to prevent DOM moves from re-initializing
8383 // TODO: Fail handling or cancellation needed?
8484 ( this as any ) . componentRef = { } ;
85- const contentChildrenTags = Array . from ( element . children ) . filter ( x => this . _componentFactory . ngContentSelectors . some ( sel => x . matches ( sel ) ) ) . map ( x => x . tagName . toLocaleLowerCase ( ) ) ;
85+ const ngContentSelectors = reflectComponentType ( this . _component ) . ngContentSelectors ;
86+ const contentChildrenTags = Array . from ( element . children ) . filter ( x => ngContentSelectors . some ( sel => x . matches ( sel ) ) ) . map ( x => x . tagName . toLocaleLowerCase ( ) ) ;
8687
87- // const toBeOrphanedChildren = Array.from(element.children).filter(x => !this._componentFactory. ngContentSelectors.some(sel => x.matches(sel)));
88+ // const toBeOrphanedChildren = Array.from(element.children).filter(x => !ngContentSelectors.some(sel => x.matches(sel)));
8889 // for (const iterator of toBeOrphanedChildren) {
8990 // // TODO: special registration OR config for custom
9091 // }
9192 let parentInjector : Injector ;
9293 let parentAnchor : ViewContainerRef ;
9394 const parents : WeakRef < IgcNgElement > [ ] = [ ] ;
94- const componentConfig = this . config ?. find ( x => x . component === this . _componentFactory . componentType ) ;
95+ const componentConfig = this . config ?. find ( x => x . component === this . _component ) ;
9596
9697 const configParents = componentConfig ?. parents
9798 . map ( parentType => this . config . find ( x => x . component === parentType ) )
@@ -148,9 +149,14 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
148149 const childInjector = Injector . create ( { providers : [ ] , parent : ( this as any ) . injector } ) ;
149150 const projectableNodes = extractProjectableNodes (
150151 element ,
151- this . _componentFactory . ngContentSelectors ,
152+ ngContentSelectors as string [ ] ,
152153 ) ;
153- ( this as any ) . componentRef = this . _componentFactory . create ( childInjector , projectableNodes , element ) ;
154+ ( this as any ) . componentRef = createComponent ( this . _component , {
155+ environmentInjector : ( ( this as any ) . injector as Injector ) . get ( EnvironmentInjector ) ,
156+ elementInjector : childInjector ,
157+ hostElement : element ,
158+ projectableNodes,
159+ } ) ;
154160 this . setComponentRef ( ( this as any ) . componentRef ) ;
155161
156162 //we need a name ref on the WC element to be copied down for the purposes of blazor.
@@ -244,7 +250,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
244250 return ;
245251 }
246252 const componentRef = ( this as any ) . componentRef as ComponentRef < any > ;
247- const componentConfig = this . config ?. find ( x => x . component === this . _componentFactory . componentType ) ;
253+ const componentConfig = this . config ?. find ( x => x . component === this . _component ) ;
248254
249255 if ( value === componentRef . instance [ property ] ) {
250256 return ;
@@ -290,7 +296,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
290296 public override getInputValue ( property : string ) : any {
291297 let returnValue = super . getInputValue ( property ) ;
292298
293- const componentConfig = this . config ?. find ( x => x . component === this . _componentFactory . componentType ) ;
299+ const componentConfig = this . config ?. find ( x => x . component === this . _component ) ;
294300 const componentRef = ( this as any ) . componentRef as ComponentRef < any > ;
295301 if ( componentRef && componentConfig ?. templateProps ?. includes ( property ) ) {
296302 returnValue = this . templateWrapper . getTemplateFunction ( returnValue ) || returnValue ;
@@ -319,7 +325,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
319325 this . schedule . delete ( queryName ) ;
320326 const componentRef = ( this as any ) . componentRef as ComponentRef < any > ;
321327 if ( componentRef ) {
322- const componentConfig = this . config ?. find ( x => x . component === this . _componentFactory . componentType ) ;
328+ const componentConfig = this . config ?. find ( x => x . component === this . _component ) ;
323329 const query = componentConfig . contentQueries . find ( x => x . property === queryName ) ;
324330 const children = this . runQueryInDOM ( this . element , query ) ;
325331 let childRefs = [ ] ;
@@ -391,7 +397,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
391397 continue ;
392398 }
393399
394- const componentType = this . _componentFactory . componentType ;
400+ const componentType = this . _component ;
395401 // TODO - look into more cases where query expects a certain base class but gets a subclass.
396402 // Related to https://github.com/IgniteUI/igniteui-angular/pull/12134#discussion_r983147259
397403 const contentQueries = parentConfig . contentQueries . filter ( x => x . childType === componentType || x . childType === componentConfig . provideAs ) ;
@@ -454,7 +460,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
454460 //#region Handle event args that return reference to components, since they return angular ref and not custom elements.
455461 /** Sets up listeners for the component's outputs so that the events stream emits the events. */
456462 protected override initializeOutputs ( componentRef : ComponentRef < any > ) : void {
457- const eventEmitters : Observable < NgElementStrategyEvent > [ ] = this . _componentFactory . outputs . map (
463+ const eventEmitters : Observable < NgElementStrategyEvent > [ ] = reflectComponentType ( this . _component ) . outputs . map (
458464 ( { propName, templateName } ) => {
459465 const emitter : EventEmitter < any > = componentRef . instance [ propName ] ;
460466 return emitter . pipe ( map ( ( value : any ) => ( { name : templateName , value : this . patchOutputComponents ( propName , value ) } ) ) ) ;
@@ -556,6 +562,6 @@ export class IgxCustomNgElementStrategyFactory extends ComponentNgElementStrateg
556562 }
557563
558564 public override create ( injector : Injector ) {
559- return new IgxCustomNgElementStrategy ( this . componentFactory , injector , this . inputMap , this . config ) ;
565+ return new IgxCustomNgElementStrategy ( this . component , injector , this . inputMap , this . config ) ;
560566 }
561567}
0 commit comments