<form *ngIf="filters">
<ng-container *ngTemplateOutlet="filterTemplate; context: {$implicit: filters}"></ng-container>
</form>
<ng-template #filterTemplate let-filters>
<ng-container *ngFor="let field of filters">
{field.something}
</ng-container>
<ng-template>
ng-container 中的filters
为空,谁能告诉我我在哪里/做错了什么?
如果您正确设置filters
数据,那么代码中没有问题:
<ng-container *ngTemplateOutlet="filterTemplate; context: {$implicit: filters}"></ng-container>
<ng-template #filterTemplate let-filters>
<ng-container *ngFor='let field of filters'>
{{field.key}}<br/>
</ng-container>
<ng-template>
工作演示(使用 ngIf/和模拟数据延迟与 setTimeout(