title: How to render templates dynamically in Angular 2?
body: <p>Im trying to select templates dynamically in a view simply by referencing them with the traditional "#" character of Angular 2.
  In my project i handle errors and display them to a user, I have a dialog component which should have its content html based dynamically injected, so thats why im using templates.</p>
  
  <p>I read some articles which shows a way of how to do it when i already know the name of the template reference in my case i dont know the name of the reference i get the name on runtime.
  I followed this guide in particular: <a href="https://www.bennadel.com/blog/3101-experimenting-with-dynamic-template-rendering-in-angular-2-rc-1.htm" rel="nofollow">https://www.bennadel.com/blog/3101-experimenting-with-dynamic-template-rendering-in-angular-2-rc-1.htm</a></p>
  
  <p>So currently my dialog component has the following view:</p>
  
  <pre><code>&lt;template #err_1 let-property1="p1" let-property2="p2"&gt;
  property1: {{p1}}
  property2: {{p2}}
  
  &lt;/template&gt;
  
  &lt;template #err_2 let-property1="p1" let-property2="p2"&gt;
  &lt;p *ngIf="p1"&gt;{{p1}}&lt;/p&gt;
  property2: {{p2}}
  &lt;/template&gt;
  
  &lt;!--The code for the template directive i took from the guide in the link above--&gt;
  &lt;tem [render]="templateRef"
       [context]="context"&gt;
  &lt;/tem&gt;
  </code></pre>
  
  <p>In my dialog.ts I have the following code:</p>
  
  <pre><code>@Component({
    selector: 'error-dialog',
    queries: {
      templateRef: new ViewChild("err_1")
    },
    templateUrl: './dialog.html'
  })
  ...
  </code></pre>
  
  <p>"TemplateRendererDirective" directive source i took from their guide from the link above.
  pay attention that what confused me: templateRef basically gets an object of: "ViewChild" even though the directive eventually gets TemplateRef instance, how this is possible?</p>
  
  <p>so only if i know which error template i want to render for example: "err_1" i just referencing it beforehand in dialog.ts, but its not the case, i want dynamically tell i want to render "err_1", "err_2" etc.. and give the context (which is the object to fill that template with data - p1, p2 for the example, also dynamically)</p>
  
  <p>Is it possible to do it?</p>