我有两个<ng-template>,我如何有条件地呈现其中一个没有外部元素的元素?
我想做这样的事情:
<ng-container *ngIf="condition ? ngTemplateOne : ngTemplatetwo"> </ng-container>
发布于 2020-02-12 21:07:41
如果你的外部元素指的是ngTemplateOutelet,你就不能。但是,在这种情况下,你可以这样实现它:
<ng-container *ngTemplateOutlet="someCondition ? template1 : template2"></ng-container>如果需要向这些模板传递要使用的object,则语法会有所不同:
<ng-container [ngTemplateOutlet]="someCondition ? template1 : template2" [ngTemplateOutletContext]="{item:item}">
</ng-container>https://stackoverflow.com/questions/60188974
复制相似问题