【发布时间】:2018-02-15 15:15:20
【问题描述】:
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 语法中引用的这些模板?
【问题讨论】:
-
我认为这是不可能的。我见过其他人有同样的问题,他们最终都使用了 ngTemplateOutlet
标签: angular templates if-statement angular-template