Angular 5.0.2
Based on the example provided on NgTemplateOutlet https://angular.io/api/common/NgTemplateOutlet
I want to know if there's a way to dynamically create a TemplateRef and then inject it into component's template.
For example let's say a component has the following template
<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'};
}
What I want is to transform this into a component with the following template
<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 TemplateRef from a string?
