Generate and Render Angular 2 Template Elements in a Component

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

Angular 2 Components have templates, but you can also create templates inside of your templates using Angular 2 ViewContainer’s createEmbeddedView for more visual control of how you want to generate elements inside of your Angular 2 templates.

Grzegorz
~ 7 years ago

Hi John, this example does not work. I got ERROR TypeError: templateRef.createEmbeddedView is not a function. Does anyone have similar issues?

Kian
~ 7 years ago

Use ng-template instead of template eg.

<ng-template #template>
  <h2>My amazing template</h2>
  <button>My amazing button</button>
</ng-template>

https://stackoverflow.com/questions/47157228/angular-5-templateref-createembeddedview-is-not-a-function