title: Angular 2 Customize display of autocomplete with dynamic <ng-content>
body: <p>I'm creating an autocomplete component and I'm trying to figure out how I should handle the "display" of the item.  I've tried using <code>ng-content</code> and rendering the item but it fails. What I want is a  way to us <code>ng-content</code> and pass "data" to the child content.  When I try to pass content it always fails and says "item" is undefined.</p>
  
  <pre><code>&lt;input-auto-complete
      [data]="searchResults"
      (onItemSelected)="onItemSelected($event)"
      (onSearch)="onSearch($event)"&gt;
         {{item.Name}}
  &lt;/input-auto-complete&gt;
  </code></pre>
  
  <p>In short I'm creating an input that does the autocomplete  / search but I can't figure out a good way to allow people to customize how they want to display the results. </p>
  
  <p>I am using ionic but my template looks like:</p>
  
  <pre><code>&lt;ion-searchbar
             [(ngModel)]="search"
              (ionInput)="updateSearch()"
              (ionCancel)="dismiss()"&gt;
  &lt;/ion-searchbar&gt;
  &lt;ion-list&gt;
    &lt;ion-item *ngFor="let item of data"
            tappable
            (click)="onItemSelected(item)"&gt;
           &lt;!-- i found a way to do something like this where they can pass a function to display --&gt;
           &lt;ng-container *ngIf="!display"&gt;
              &lt;pre&gt;{{item|json}}&lt;/pre&gt;
            &lt;/ng-container&gt;
            &lt;ng-container *ngIf="display"&gt;
              {{display(item)}}
            &lt;/ng-container&gt;
  
  
            &lt;!-- could not get this to work this would be my preference allow people to put whatever in here and it would get rendered and passed "item" --&gt;
           &lt;!-- if i enable this it breaks  &lt;ng-content &gt;&lt;/ng-content&gt;   -&gt;
    &lt;/ion-item&gt;
  &lt;/ion-list&gt;
  </code></pre>
  
  <p>When this renders it crashes and says can't read Name of undefined. It's not passing anything to the ng-content.</p>
  
  <p>Can anyone suggest a solution for this?  Let me know if things dont make sense.</p>