I'm currently facing a dilemma without a clear solution in sight.
I have created some custom components that utilize content projection and multi slot transclusion.
For instance, I have a Card (Bootstrap) and I want to customize elements like the header, body, or a basic footer within a template.
<div class="card">
<ng-content select="[card-header]">
<!-- Anything inserted here will vanish :-) -->
</ng-content>
<ng-content select="[card-body]">
<!-- Anything inserted here will vanish :-) -->
</ng-content>
<ng-content select="[card-list]">
<!-- Anything inserted here will vanish :-) -->
</ng-content>
</div>
When using my component, the code would appear as follows:
<vng-control-card>
<span card-header>
<fa-icon [icon]="['fas','user']"></fa-icon> User list
</span>
<div card-list>
<vng-control-userlist [showSendButtons]="false"></vng-control-userlist>
</div>
</vng-control-card>
As observed, there is no body, only a card-list and a header. However, the body is still being rendered. How can I verify if there is any content for a slot? If the slot is empty, it should not be displayed.
For example: Rendered userlist (component)
The yellow portion represents the empty slot "card-body" which is rendered and appended to the dom despite being empty.
Is there a solution to check and prevent this from happening?