title: Get ViewChildren Template By Id
body: <p>In my component I get a list of its markup templates by using ViewChildren:</p>
  
  <pre><code>@ViewChildren(TemplateRef) private _templates: QueryList&lt;TemplateRef&lt;unknown&gt;&gt;;
  </code></pre>
  
  <p>In Angular8 I was not able to filter them by an Id, so i needed to look for an internal property - which was somehow a bit hacky:</p>
  
  <pre><code>let template = this._templates.find(t =&gt; (&lt;any&gt;t)._def.references[id]) : null;
  </code></pre>
  
  <p>Now, with Angular 9, this doesn't work anymore. I checked the object and found a new "hack":</p>
  
  <pre><code>this._templates.find(t =&gt; (&lt;any&gt;t)._declarationTContainer?.localNames?.includes(id)) : null;
  </code></pre>
  
  <p>But is there any new or clean solution for this scenario?</p>
  
  <p>Still hoping for a solution that works without a custom Directive, eg. MatTab probably does something similar, too:</p>
  
  <pre><code>&lt;mat-tab&gt;
      &lt;ng-template mat-tab-label&gt;
          ...
      &lt;/ng-template&gt;
  
      &lt;ng-template matTabContent&gt;
          ...
      &lt;/ng-template&gt;
  &lt;/mat-tab&gt;
  </code></pre>