title: How to use ResolveComponentFactory() but with a string as a key
body: <p>What I'm trying to do:</p>
  <ul>
  <li>Use something similar to the &quot;resolveComponentFactory()&quot;, but with a 'string' identifier to get Component Factories.</li>
  <li>Once obtained, start leverage the &quot;createComponent(Factory)&quot; method.</li>
  </ul>
  <p>Plnkr Example -&gt; <a href="https://plnkr.co/edit/OjDaqijUTVIbzMX4JZ5c?p=preview" rel="nofollow noreferrer">enter link description here</a></p>
  <p>In the example, you will see the <strong><code>AddItem</code></strong> method</p>
  <pre class="lang-js prettyprint-override"><code>addItem(componentName:string):void{
      let compFactory: ComponentFactory;
  
      switch(componentName){
          case &quot;image&quot;:
              compFactory = this.compFactoryResolver.resolveComponentFactory(PictureBoxWidget);
              break;
          case &quot;text&quot;:
              compFactory = this.compFactoryResolver.resolveComponentFactory(TextBoxWidget);
              break;
      }
      
      //How can I resolve a component based on string
      //so I don't need to hard cost list of possible options
      
      this.container.createComponent(compFactory);
  }
  </code></pre>
  <p>The &quot;compFactoryResolver:ComponentFactoryResolver&quot; is injected in the contructor.</p>
  <p>As you will note, having to hard code every permutation in a switch statement is less than ideal.</p>
  <p>when logging the ComponentFactoryResolver to the console, I've observed that it contains a Map with the various factories.</p>
  <pre><code>CodegenComponentFactoryResolver {_parent: AppModuleInjector, _factories: Map}
  </code></pre>
  <p>However, this map is a private and can't be easily accessed (from what I can tell).</p>
  <p>Is there a better solution then somehow rolling my own class to get access to this factory list?</p>
  <p>I've seen a lot of messages about people trying to create dynamic components. However, these are often about creating components at run time. the components in question here are already pre-defined, I am stuck trying to access factories using a string as a key.</p>
  <p>Any suggestions or advice are much appreciated.</p>
  <p>Thank you kindly.</p>