ng-template和ng-container的巢狀使用

汪子熙發表於2020-10-07

原始碼:

<h4>Jerry: {{position}}</h4>
<div *ngIf="components[0]">
<h5>Component uid: {{ components[0].uid }}</h5>
<h6>Type code: {{ components[0].typeCode }}</h6>
</div>
<h4>end</h4>
<ng-template
  [cxOutlet]="position"
  [cxOutletContext]="{ components$: components$ }"
>
<div>before ng-template</div>
  <ng-template
    *ngFor="let component of components"
    [cxOutlet]="component.flexType"
    [cxOutletContext]="{ component: component }"
    [cxOutletDefer]="getComponentDeferOptions(component.flexType)"
    (loaded)="isLoaded($event)"
  >
  <div>before ng-container,type: {{ component.flexType}}</div>
    <ng-container [cxComponentWrapper]="component"></ng-container>
  <div>after ng-container</div>
  </ng-template>
<div>after ng-template</div>
</ng-template>

在這裡插入圖片描述

相關文章