How to use templateRef from other component template file?
I have BatmanComponent, SpidermanComponent and a JokerComponent. Some of them have similar features, so that I decided to create a HumanComponent, and put all reusable HTML codes in that file, as such:
Note: the HumanComponent will never be used, it is just a file that consists all default template.
<!-- human.component.ts -->
<ng-template #eye>
Eyes: {{ size }}
</ng-template>
<ng-template #body>
Body: bust {{ x[0] }}, waist {{ x[1] }}, hip {{ x[2] }}
</ng-template>
May I know how to inject those template (from human.component.ts) and use it inside the batman.component.ts, etc...?
I know I can do it as such: (only if the template code is being copy-paste inside the batman, spiderman, and joker HTML files)
<!-- batman.component.ts -->
<ng-container *ngTemplateOutlet="eye; context: contextObj"></ng-container>
<ng-template #eye> ... </ng-template> <!-- need to copy/paste here, and use it locally -->
May I know how can I export templateRef to other files, and re-use them? I don't want to copy and paste similar codes across those files, I hope I can have a default template file, and just export those codes to whoever want it. Is it possible?
Update:
After reading the comments, I decided to use the reusable component rather than this "techniques"... Probably, the Angular team is trying hard to optimize the reusable component approach (as @artyom, @rafael, @ibenjelloun suggested), then probably just follow their path will be wiser... Haha...
Anyway, thanks.