31

I need to add the tappable directive to the ion-card component inside a custom component. I use an @Input() myInputBool, something like:

<ng-container *ngIf="myInputBool">
    <ion-card>
        <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 it does not work because there are no "render" option. So far my workaround was adding an inexistent variable in the ng-container

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

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

distante
  • 6,438
  • 6
  • 48
  • 90

1 Answers1

55

I would use ngTemplateOutlet instead of render option:

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

See also

yurzui
  • 205,937
  • 32
  • 433
  • 399