I have a component that has two TemplateRefs
@ViewChild('optionContent') optionContent: TemplateRef<unknown>; @ViewChild('selectContent') selectContent: TemplateRef<unknown>;
with template:
<ng-template #optionContent>
<ng-content select="[option]"></ng-content>
</ng-template>
<ng-template #selectContent>
<ng-content select="[select]"></ng-content>
</ng-template>
I am passing the above component in its parent and checking if selectcontent exists, it should render the selectcontent else optioncontent but I can not come up with a condition. I am using the following logic in the parent template but it is not working:
<ng-container [ngTemplateOutlet]="state?.selectedItem?.selectContent ?? state?.selectedItem?.optionContent" ></ng-container>
Is there any other way to acheive this?
I tried with the following condition:
<ng-container [ngTemplateOutlet]="state?.selectedItem?.selectContent ?? state?.selectedItem?.optionContent" ></ng-container>
You wanna check if any
ng-content
is empty, right? Here is a possible solution on Stackoverflow.So in short words: You can handle it with
css
but your solution is absolutely fine.CSS Example
HTML
CSS