title: loading component to dynamically generated templates
body: <p>i am trying to load component dynamically using ComponentFactoryResolver</p>
  
  <p>here is my code </p>
  
  <pre><code>import {Component, ComponentRef, ViewContainerRef, ComponentFactoryResolver,
          ViewChild, OnInit, OnDestroy, AfterViewInit} from '@angular/core';
  import {MyDynamicComponent} from './mycomponent';
  
  @Component({
    selector: 'home',
    template: '&lt;template #Component1&gt;&lt;/template&gt;'
  })
  export class Home implements AfterViewInit {
  
  private componentReference: ComponentRef&lt;any&gt;;
  
  @ViewChild('Component1', { read: ViewContainerRef })
  private dynamicTarget: ViewContainerRef;
  
  
    constructor(private resolver: ComponentFactoryResolver) {}
  
    ngAfterViewInit() {
   let componentFactory = this.resolver.resolveComponentFactory(MyDynamicComponent);
    this.componentReference = this.dynamicTarget.createComponent(componentFactory);
  
  
     }
  </code></pre>
  
  <p>this code is working fine 
  But in my actual implementation the <code>&lt;template #Component1&gt;&lt;/template&gt;</code> will be generated dynamically in that case it is not working because the template id is not yet generated when it trying to load the component. is there any way to use the @viewChild after finish generating of the dom. Any help is really appreciated.</p>