title: How do you pass the ngFor template input variable to an ngTemplate via an ngIf?
body: <p>I am trying to create a table that uses a different <code>ng-template</code> for certain cells, depending on some data in the cell. (In this case, if the cell is in the "Entity" column, I want a template that shows a photo as well as the regular data.)</p>
  
  <p>Using <code>*ngIf</code> I'm easily able to switch the <code>ng-template</code> in the table. But when I'm in the switched template, I no longer know how to access the cell data  which is coming from the surrounding <code>ngFor</code> loop.</p>
  
  <p>The template input variable is called "cell".</p>
  
  <p>I thought I could pass <code>cell</code> to the new template using <code>let-value="cell"</code> but it doesn't work. Inside the template, the variable "value" is undefined. I also checked to see if "cell" is in scope without me even using a <code>let-</code>, but it's not, either.</p>
  
  <p>How do I access the "cell" template input variable inside the various <code>ng-templates</code> that I swap in with the <code>*ngIf</code>?</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr *ngFor="let row of tableArray"&gt;
      &lt;td *ngFor="let cell of row"&gt;
        &lt;ng-container *ngIf="cell.column === 'Entity' then photoTemplate else cellTemplate"&gt;&lt;/ng-container&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;ng-template #cellTemplate let-value="cell"&gt;
    {{value.display}} &lt;&lt;&lt;==========DOESN'T WORK
  &lt;/ng-template&gt;
  
  &lt;ng-template #photoTemplate&gt;
    {{cell.display}} &lt;&lt;&lt;======= DOESN'T WORK EITHER WITHOUT THE let-
  &lt;/ng-template&gt;
  </code></pre>
  
  <p>Sorry for the newbie question. I come from AngularJS and Angular 5 is very new to me. I've searched the docs but I can't find anything.</p>
  
  <p>thanks</p>
  
  <p>John</p>
  
  <p>PS This is a slight variation on the <a href="https://stackoverflow.com/questions/43726749/pass-variable-in-angular-2-template">suggested duplicate</a> because I'm trying to use dynamic templates with ngIf, which is a complication others may encounter, but not discussed in the duplicate.</p>
  
  <p>In the end though the approach is the same. I had to abandon ngIf and use references to templates. (See below). </p>
  
  <p>Though I note, following the answer in the suggested duplicate didn't work for me: I had to pass the context variable as a key value pair <code>context:{cell:cell}</code> rather than just as <code>context:cell</code>.</p>