<p dir="auto">When attempting to use <code class="notranslate">exportAs</code> with a template-based directive, the following behaviour occurs:</p>
<p dir="auto">(1) <strong>When used with <code class="notranslate">*</code> syntax:</strong> You get the error "There is no directive with "exportAs" set to "foo"" despite this not being true<br>
(2) <strong>When used with <code class="notranslate">template</code></strong>: You don't get an error, but the export is null, so any method calls or property access will error</p>
<p dir="auto"><del>The only way for the export to work is:</del></p>
<p dir="auto"><del>(1) Using <code class="notranslate">&lt;template&gt;</code></del><br>
<del>(2) and specifying exportAs, despite having to... [edit: not actually necessary for workaround]</del><br>
<del>(3) manually set the local with `ViewRef.setLocal("exportAsName", this);</del></p>
<p dir="auto"><del>Additionally, in no case is the exported variable accessible in the external context. When set with <code class="notranslate">setLocal</code> it can only be accessed inside the template. (It makes sense that setLocal only works inside the template, so this is more a consequence of the overall divergent behaviour)</del></p>
<p dir="auto">(While that's a workaround to get at the variable inside the template, it doesn't constitute a "way for the export to work" since it's somewhat unrelated feature-wise)</p>
<p dir="auto">Demonstration plunkr: <a href="http://plnkr.co/edit/jXYxQ6NYk7tec4QNf355?p=preview" rel="nofollow">http://plnkr.co/edit/jXYxQ6NYk7tec4QNf355?p=preview</a></p>
<p dir="auto">If you want to use a <code class="notranslate">TemplateRef</code> to instantiate an embedded View anywhere other than in that template's location (i.e., with its own <code class="notranslate">ViewRef</code>), the inability to grab the TemplateRef (or a directive instance) on the template element becomes cumbersome. The only real way to accomplish it now is to use <code class="notranslate">@ViewChild</code> / <code class="notranslate">@ViewChildren</code> to retrieve some decorating <code class="notranslate">Directive</code> that exposes the TemplateRef.</p>
<p dir="auto">For example:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;component-with-popup [popup]=&quot;content&quot;&gt;&lt;/component-with-popup&gt;

&lt;template popup-content #content&gt;
  This is the template content!
&lt;/template&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">component-with-popup</span> <span class="pl-c1">[popup]</span>="<span class="pl-s">content</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">component-with-popup</span><span class="pl-kos">&gt;</span>

<span class="pl-kos">&lt;</span><span class="pl-ent">template</span> <span class="pl-c1">popup-content</span> <span class="pl-c1">#content</span><span class="pl-kos">&gt;</span>
  This is the template content!
<span class="pl-kos">&lt;/</span><span class="pl-ent">template</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">This doesn't work, since the assumption is that <code class="notranslate">#content</code> is for something <em>in</em> the template rather than the template itself.</p>
<h3 dir="auto">Proposal:</h3>
<p dir="auto">Add a new syntax for referencing the template itself:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;component-with-popup [popup]=&quot;content&quot;&gt;&lt;/component-with-popup&gt;

&lt;template popup-content template-var-content&gt;
  This is the template content!
&lt;/template&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">component-with-popup</span> <span class="pl-c1">[popup]</span>="<span class="pl-s">content</span>"<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">component-with-popup</span><span class="pl-kos">&gt;</span>

<span class="pl-kos">&lt;</span><span class="pl-ent">template</span> <span class="pl-c1">popup-content</span> <span class="pl-c1">template-var-content</span><span class="pl-kos">&gt;</span>
  This is the template content!
<span class="pl-kos">&lt;/</span><span class="pl-ent">template</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">This uses <code class="notranslate">template-var-</code> as the prefix for the variable over the standard <code class="notranslate">var-</code>. Since this is going to be a somewhat uncommon use-case, a shorthand syntax isn't strictly necessary.</p>
<p dir="auto">If desired, possible shorthand syntaxes:<br>
<code class="notranslate">&lt;template @content&gt;</code><br>
<code class="notranslate">&lt;template *#content&gt;</code><br>
<code class="notranslate">&lt;template **content&gt;</code><br>
<code class="notranslate">&lt;template ##content&gt;</code><br>
<code class="notranslate">&lt;template !#content&gt;</code><br>
<code class="notranslate">&lt;template 😱content&gt;</code></p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vsavkin/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vsavkin">@vsavkin</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tbosch/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tbosch">@tbosch</a></p>