How to make ng container or ng template without * ngIf?

I need to add a directive tappable

to a component ion-card

inside a custom component. I am using @Input() myInputBool

, something like:

<ng-container *ngIf="myInputBool">
    <ion-card tappable>
        <ng-container render="myContent"></ng-container>
    </ion-card>
</ng-container>

<ng-container *ngIf="!myInputBool">
    <ion-card tappable>
        <ng-container render="myContent"></ng-container>
    </ion-card>
</ng-container>

<ng-container #myContent>
    This is my content
</ng-container>

      

Of course this doesn't work because there is no "render" option. So far, my workaround has been to add a nonexistent variable to ng-container

<ng-container *ngIf="thisVariableDoesNotExist else myContent"> </ng-container>

      

But it feels bad and hacked. Is there a better way to do this?

+3


source to share


1 answer


I would use ngTemplateOutlet

instead of the option render

:

<ng-container *ngTemplateOutlet="myContent"></ng-container>

      



see also

+4


source







All Articles