angular 5: templateRef.createEmbeddedView is not a function

According to angular 5 changelog:

The compiler option enableLegacyTemplate is now disabled by default as
the element was deprecated since v4. Use <ng-template>
instead.

So you should use ng-template instead of template:

<ng-template #tpl>
   <h1>ViewContainerRef</h1>
</ng-template>

Stackblitz Example

or set enableLegacyTemplate to true:

platformBrowserDynamic().bootstrapModule(AppModule, { enableLegacyTemplate: true })

Stackblitz Example

But you should know that

The option enableLegacyTemplate and the <template> element will both be removed in Angular v6.

Leave a Comment

File not found.