I am trying to improve my code rather than having conditions, so I decided to create a directive or maybe a pipe if possible that could help me print the title of a tab depending on its type (string or templateRef), my code is the following, this code is used in my Tabs/Tab component, but also in my Stepper/step component, so I believe it would be great to create something reusable. I've tried doing it with ElementRef, Renderer2, ViewContainerRef, TemplateRef... but I was unsuccessful.
<ng-container *ngIf="tab.isLabelTemplate">
<ng-container *ngTemplateOutlet="tab.title">
</ng-container>
</ng-container>
<ng-container *ngIf="!tab.isLabelTemplate">{{ tab.title }}</ng-container>
The isLabelTemplate looks like this:
get isLabelTemplate(): boolean {
return this.title instanceof TemplateRef;
}
Thanks a lot :)