0

这是我们应用程序当前代码的片段

<gridster [options]="options" *ngIf="widgets?.length > 0 && !isWidgetOnly">
 <gridster-item class="gridster-container" *ngFor="let widget of widgets" [item]="widget" [ngClass]="{'resize': someCheck(widget)}">

  /*Current container*/
  <ng-container *ngIf="widget.type === 'someType'">
    <ng-container *ngTemplateOutlet="someTypeWrapper; context: {widget : widget}"></ng-container>
  </ng-container>

  /*Would like to do something like this*/
  <ng-container>
    <ng-container *ngTemplateOutlet="getOutletTemplate(widget.type)"></ng-container>
  </ng-container>
  
 </gridster-item>
</gridster>

<div class="chart-container" *ngIf="widgets?.length > 0">
 <ng-container *ngFor="let widget of widgets">
  <ng-container [ngSwitch]="widget.type?.trim()">
   <ng-container *ngSwitchCase="'someType'">
      <some-wrapper></some-wrapper>
    </ng-container>
  </ng-container>
 </ng-container>
</div>

并且,在组件文件中:

  getOutletTemplate(type: string) {
   switch (typeype) {
    case 'someType':
     return 'someWrapper; context: {widget : widget}';
    default:
     return '';
   }
  }

有可能这样做吗?我得到了一堆解析器错误,所以我很好奇我是否正在试图让这个工作正常进行。

谢谢!

4

0 回答 0