title: Angular 2: functions/methods on click inside dynamic template (dynamic component)
body: <p>Following the example below:</p>
  
  <p><a href="https://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-dynamic-component-with-angular">How can I use/create dynamic template to compile dynamic Component with Angular 2.0?</a></p>
  
  <p>I developed my own template generator, which gets the HTML content directly from a variable.
  Here it is:
  <a href="http://plnkr.co/edit/2Sv1vp?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/2Sv1vp?p=preview</a></p>
  
  <p>Now, my question is... if template content has to interact with the component, for example with a function to execute on click... how can I do that?</p>
  
  <p>Here my app.component.ts</p>
  
  <pre><code>import { Component }          from '@angular/core';
  
  @Component({
    selector: 'my-app',  
    template: `
      &lt;div&gt;
        &lt;h2&gt;An app with DYNAMIC content&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;dynamic-detail [tmpl]="tmpl1" [entity]="entity"&gt;&lt;/dynamic-detail&gt;
        &lt;dynamic-detail [tmpl]="tmpl2" [entity]="entity"&gt;&lt;/dynamic-detail&gt;
      &lt;/div&gt;`,
     })
     export class AppComponent { 
       private tmpl: string;
       private entity: any;
  
       constructor() {
         this.entity = { 
           code: "ABC123",
           description: "A description of this Entity",
           nome: "Bea"
         };
  
         this.tmpl1 = '&lt;h2&gt;Sono {{entity.nome}}, il primo template&lt;/h2&gt;';
         this.tmpl2 = '&lt;a (click)="printSomething()"&gt;Sono il secondo template&lt;/a&gt;';
        }
  
      printSomething() {
        console.log("Hello World");
      }
  }
  </code></pre>
  
  <p>When I try click on "Sono il secondo template", it should execute <code>printSomething()</code> function, but instead I obtain this error: </p>
  
  <pre><code> Error in ./CustomDynamicComponent class CustomDynamicComponent - inline template:0:0 caused by: self.context.printSomething is not a function
  </code></pre>