Angular 2:如何从外部文件加载TemplateRef

lex*_*ren 6 templates angular

我正在使用可自定义的单元格配置创建网格组件.目前,为了能够在单元配置中设置自定义单元组件,我在视图中存储了一大堆模板,如下所示:

<template let-row="row" #nameCell>
  <name-cell [row]="row"></name-cell>
</template>
Run Code Online (Sandbox Code Playgroud)

在视图中获取模板并存储在网格配置中:

  @ViewChild('nameCell') nameCell: TemplateRef<any>;
  ...
  column.customCell = nameCell
Run Code Online (Sandbox Code Playgroud)

而不是在网格单元格中使用此模板:

    <template
      *ngIf="column.customCell"
      [ngTemplateOutlet]="column.customCell"
      [ngOutletContext]="{ row: row}">
    </template>
Run Code Online (Sandbox Code Playgroud)

这有效,但看起来凌乱和肮脏.有没有办法从外部文件动态加载TemplateRef?