Angular的NgTemplateOutlet允许您将上下文传递给出口以进行属性绑定 .
<ng-container *ngTemplateOutlet="eng; context: {$implicit: 'World'}"></ng-container>
<ng-template #eng let-name><span>Hello {{name}}!</span></ng-template>
Angular的 *ngIf
允许您根据布尔条件嵌入一个或另一个模板:
<ng-container *ngIf="isConditionTrue; then one else two"></ng-container>
<ng-template #one>This shows when condition is true</ng-template>
<ng-template #two>This shows when condition is false</ng-template>
如何将上下文传递给 *ngIf
语法中引用的这些模板?
2 回答
为什么不这样做:
实际上你可以输入你的条件到ngTemplateOutlet(并摆脱ngIf) .