title: How to store the variable of an asynchronous callback function
body: <p>I am developing a chrome extension and I am trying to output the selected text on the tab in a textarea inside the plugin.</p>
  
  <p>The function to get the selected text works very well but I can't set the value to the textarea element inside the plugin.</p>
  
  <p><strong>Question:</strong> How do I correctly store the value to be able to then pass it to the textarea with data-binding?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div&gt;
      &lt;p&gt;Here will appear the selected text :&lt;/p&gt;
      &lt;textarea name="selectedText" id="selectedText" [(ngModel)]="selectedText"&gt;&lt;/textarea&gt;
      &lt;button (click)="getSelectedText()"&gt;Get the selected text&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>TS:</strong></p>
  
  <pre><code>export class CaptureComponent {
      selectedText = '';
  
      getSelectedText() {
          chrome.tabs.executeScript( {
              code: 'window.getSelection().toString();'
          }, function(selection) {
              this.selectedText = selection[0];
          });
      }
  }
  </code></pre>
  
  <p>The <code>selection[0]</code> is working fine so I guess that the way I am trying to store the data is not correct, but I can't seem to find what to change it to.</p>