0

In Angular 8 is there a way to get an array of all the Components that are available for dynamic loading? I'm passing a string of the Component name from an external source. I'd like to conditionally confirm that the Component exists before attempting to create it and inserting into the view.

Currently I'm importing each component into a Service and statically comparing the constructor names against my dynamic value. While this works it will become increasingly difficult to manage as the number of dynamic components grows so, I'd like to be able to get an array of the rendered available Components, including those included in entryComponents.

CIll
  • 35
  • 1
  • 6

1 Answers1

0

Discovered the answer as part of another post regarding the loading of dynamic components.

This returns an array of rendered components, including those added via entryComponents:

this.componentFactoryResolver['_factories'].values() 

This will return a factory class of the component where the string 'SystemMessageComponent' is matching string of a component included in the entryComponents array:

const factories = Array.from(this.componentFactoryResolver['_factories'].values());
const factoryClass = <Type<any>>factories.find((x: any) => x.componentType.name === 'SystemMessageComponent');
CIll
  • 35
  • 1
  • 6