我需要将tappable指令添加到自定义组件内的离子卡组件.我使用@Input()myInputBool,类似于:
<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>
当然它不起作用,因为没有“渲染”选项.到目前为止,我的解决方法是在ng-container中添加一个不存在的变量
<ng-container *ngIf="thisVariableDoesNotExist else myContent"> </ng-container>
但它感觉很糟糕和黑客.有更好的方法吗?
解决方法
我会使用ngTemplateOutlet而不是render选项:
<ng-container *ngTemplateOutlet="myContent"></ng-container>
也可以看看