title: Angular2, manually resolve a type by string/name
body: <p>Is it possible to manually resolve a component by only knowing it's name?</p>
  
  <p>I have a string variable which will contain the name of a component, lets say "UserService"</p>
  
  <p>I need to be able to resolve this type, I've looked at <code>Injctor</code>, I can see from the documenation there is a <code>resolve()</code> and <code>resolveAndCreate()</code> (<a href="https://angular.io/docs/ts/latest/api/core/Injector-class.html" rel="nofollow">https://angular.io/docs/ts/latest/api/core/Injector-class.html</a>)</p>
  
  <p>but I don't have the Type. </p>
  
  <p>Thanks</p>
  
  <p>Steve</p>
  
  <p><strong>EDIT</strong>: tried the following:</p>
  
  <pre><code>System.import("path/to/service").then(p=&gt;{
  
       var injector = Injector.resolveAndCreate([p[this.serviceName]]);//works
  
       var serviceInstance = injector.get(p[this.serviceName]); //Fails with "No provider for Http! (UserService -&gt; Http)".
  
  
  });
  </code></pre>
  
  <p>I have <code>Http</code> available, it's been provided during bootstrap and this works fine for other parts of the application.</p>
  
  <pre><code>bootstrap(AppComponent, [
      ROUTER_PROVIDERS, Http, HTTP_PROVIDERS, UrlBuilderService,
      provide(LocationStrategy, { useClass: HashLocationStrategy }),
      provide('notification', { useClass: NotificationService })
  ]);
  </code></pre>
  
  <p>Any idea's?</p>
  
  <p><strong>Further Edit</strong>:</p>
  
  <p>I now call the <code>resolveAndCreate</code> like this: </p>
  
  <pre><code>var injector = Injector.resolveAndCreate([p[this.serviceName], Http]);
  </code></pre>
  
  <p>which failed with </p>
  
  <blockquote>
    <p>No provider for ConnectionBackend! (UserService -> Http ->
    ConnectionBackend)</p>
  </blockquote>
  
  <p>So i called it like this: </p>
  
  <pre><code>var injector = Injector.resolveAndCreate([p[this.serviceName], Http, ConnectionBackend]);
  </code></pre>
  
  <p>which failed with some other missing stuff.</p>
  
  <p>Changed to this</p>
  
  <pre><code>var injector = Injector.resolveAndCreate([p[this.serviceName], HTTP_PROVIDERS]);
  </code></pre>
  
  <p>and now all is working.</p>
  
  <p><strong>What I do not understand is why it's not automatically resolving these components because i have them provided during bootstrap.</strong></p>