3

I am trying add a button in addition to the element's template. Where can I define the template of the additional element which needs to be added?

this.view.createEmbeddedView(this.template);

The above code lets me add only TemplateRef. Where to define the <template> and how to get the reference TemplateRef of it?

I tried doing this.el.nativeElement.insertAdjacentHTML('beforeend','<div>One</div>'). This adds the element but the added html is not Angular compiled.

halfer
  • 19,824
  • 17
  • 99
  • 186
Lakshay Dulani
  • 1,710
  • 2
  • 18
  • 45
  • 1
    There is no public API to create a `TemplateRef`. You can create a component that contains this button and add the component instead with `this.view.createComponent()` (not checked if `this.view` actually provides `createComponent()` but I assume so. – Günter Zöchbauer Mar 08 '17 at 10:37
  • 1
    added html is not angular compiled???? – Roman C Mar 08 '17 at 10:39
  • 1
    Here is a good example of what @GünterZöchbauer suggest: [https://stackoverflow.com/questions/43944487/adding-a-component-to-a-templateref-using-a-structural-directive](https://stackoverflow.com/questions/43944487/adding-a-component-to-a-templateref-using-a-structural-directive) – westor Sep 11 '18 at 16:45

0 Answers0