Angular 2: How to load TemplateRef from an external file

I am creating a grid component with a custom cell configuration. Currently, since I can set up a custom cell element in a cell configuration, I store a whole bunch of templates, for example:

<template let-row="row" #nameCell>
  <name-cell [row]="row"></name-cell>
</template>

Getting the template and saving it in the grid configuration:

  @ViewChild('nameCell') nameCell: TemplateRef<any>;
  ...
  column.customCell = nameCell

And how to use this template in the grid cell:

    <template
      *ngIf="column.customCell"
      [ngTemplateOutlet]="column.customCell"
      [ngOutletContext]="{ row: row}">
    </template>

It works, but it looks dirty and dirty. Is there a way to dynamically load a TemplateRef from an external file?

+4
source share

Source: https://habr.com/ru/post/1659391/


All Articles