title: How to use templateRef?
body: <p>I am trying to find a way to dynamically construct a template in Angular2. I was thinking templateRef might provide a way to do this. But I could be wrong.</p>
  
  <p><a href="https://github.com/dsebastien/angularConnect2015London/blob/master/14%20Better%20concepts%20less%20code%20in%20Angular%202.md" rel="noreferrer">I found an example of templateRef being used here.</a></p>
  
  <p>I was looking at templateRef in this example. I noticed the syntax is <code>[ng-for-template]</code> I also tried <code>[ngForTemplate]</code> cause I know this has changed recently. </p>
  
  <p><strong>So at the moment I have this:</strong></p>
  
  <pre><code>import {Component, TemplateRef} from 'angular2/core';
  
  @Component({
      selector : 'body',
      template : `
          &lt;template [ngForTemplate]="container"&gt;
              &lt;div class="container"&gt;&lt;/div&gt;
          &lt;/template&gt;
      `
  })
  
  export class App
  {
      @ContentChild(TemplateRef) container;
  
      constructor() {}
  
      ngAfterContentInit()
      {
          console.log(this);
      }
  }
  </code></pre>
  
  <p><strong>This example throws an error:</strong></p>
  
  <blockquote>
    <p>Can't bind to 'ngForTemplate' since it isn't a known native property</p>
  </blockquote>
  
  <p>So firstly I am wondering. What is the right way to do this? <a href="https://angular.io/docs/ts/latest/api/core/TemplateRef-class.html" rel="noreferrer">The docs don't provide any examples.</a></p>
  
  <p>Secondly, is there a good way I can add new template logic to my template or dynamically construct a template? The structure of the application can be a very large amount of different structural combinations. So if possible I would like to see if there is a way I can do this without having a huge template with a bunch of different ngIf and ngSwitch statements.. </p>
  
  <p>My question is really the first part about templateRef. But any help or suggestions on the second part is appreciated. </p>