Angular 5.0.2 Based on the above NgTemplateOutlet https://angular.io/api/common/NgTemplateOutlet
I want to know if there is a way to dynamically create a TemplateRef and then enter it into the component template.
For example, let's say that the component has the following pattern
<ng-container *ngTemplateOutlet="eng; context: myContext"></ng-container> <ng-template #eng let-name><span>Hello {{name}}!</span></ng-template>
component code
class NgTemplateOutletExample { myContext = {$implicit: 'World'}; }
I want to convert this to a component with the following pattern
<ng-container *ngTemplateOutlet="eng; context: myContext"></ng-container>
and component code like this
class NgTemplateOutletExample { eng:TemplateRef = this.createTemplateRef('<ng-template #eng let-name><span>Hello {{name}}!</span></ng-template>'); myContext = {$implicit: 'World'}; }
Is it possible to create a TemplateRef from a string?
source share