Tuesday, May 1, 2018

Did you know that you may grab ahold of a template as an ViewChild in an Angular 4 application?

If a template inside of the template for a component looks like so:

<ng-template #myRef let-item>
   <span class="whatever">{{item?.cockroachPower}}</span>
</ng-template>

 
 

Back on the TypeScript side of a component you just need something like this:

@ViewChild('myRef') myRef: TemplateRef<any>;

No comments:

Post a Comment