I'm setting up ngTemplateOutlet inside *ngFor like in below code snippet
<ul>
<li *ngFor="let item of list">
<ng-container [ngTemplateOutlet]="item.type"></ng-container>
</li>
</ul>
Where list = [ {type: 'templateOne'}, {type: 'templateTwo'} ]
and i have defined templates like below.
<ng-template #templateOne></ng-template>
<ng-template #templateTwo></ng-template>
The above template snippet is throwing error with message undermentioned
TypeError: templateRef.createEmbeddedView is not a function
at ViewContainerRef_.push../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createEmbeddedView (core.js:21600)
at NgTemplateOutlet.push../node_modules/@angular/common/fesm5/common.js.NgTemplateOutlet.ngOnChanges (common.js:4026)
at checkAndUpdateDirectiveInline (core.js:22085)
Since item.type
used in ngTemplateOutlet
is of type string i am suspecting it is not getting resolved to templateReference variable.
How can i convert string to a templateReference instance?
Demonstration - See this link for example and verify console for the error