title: Calling a TS Function from Script
body: <p>I'm Using a external JS from an external enterprise. Is mandatory use this script online and not import it.</p>
  <p>one of the complexity is that they've his own html tag to call a functions that are inside from a script tag. I've created this script from typescript side to control some variables, but i need to call a function to have a value needed in the end of the flux.</p>
  <p>So, in short, I need call a TypeScript Function from this script tag created.</p>
  <p>here some code:</p>
  <pre><code>    let script = document.createElement('script');
      script.type = `text/javascript`;
      script.text = `
      var success = function (data) {
          let transactions= ${JSON.stringify(this.transactions)};
          let internalId = this.getInternalId('Hello there!'); -----&gt; The TS Function that I want to call
      };`;
      document.getElementsByTagName('body')[0].appendChild(script);
      
      getInternalId(value:string):void {
      console.log('a');
     }
  </code></pre>
  <p>greetings!</p>
  <p><strong>UPDATE</strong></p>
  <p>I tried to abstract the function in the HTML tag like this:</p>
  <pre><code>    [attr.data-order-id]=&quot;success&quot;
  </code></pre>
  <p>and in the ts file like this:</p>
  <pre><code>    success = (data:any ) =&gt; {
      debugger;
      alert(JSON.stringify(this.transactions;));
    };
  </code></pre>
  <p>But I lost every reference of the proyect and somehow it function is executed from other file:</p>
  <p><a href="https://i.stack.imgur.com/TBwhI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TBwhI.png" alt="The function is executed from another file. on the left tab is the ts file where function is declarated functions" /></a></p>
  <p>The function is executed from another file. On the left tab is the ts file where function is declarated.</p>