title: Getting JavaScript result in Angular
body: <p>I'm using a third party JS I'm calling from Angular:</p>
  
  <pre><code>import { Component } from '@angular/core';
  declare var SomeApi: any;
  
  @Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
  })
  export class AppComponent {
    firstName: string;
  
    onStartTest() {
      SomeApi.runTest();    
  
      function onTestCompleted(testResult) {
        //Can get testResult.FirstName
        this.firstName = testResult.FirstName;
      }
    }      
  }
  </code></pre>
  
  <p>I can successfully run the SomeApi.runTest() in Angular and when it finished I can get the testResult and its properties like FirstName and display to HTML. But the problem is I can't pass this to the local Angular variable which is firstName: string in this case. The component I think finishes up as the .runTest() runs in async.</p>
  
  <p>I also tried running a service inside the function so that I can pass the data to a service after onTestCompleted():</p>
  
  <pre><code>constructor(private dataService: DataService) {}
  
  function onTestCompleted(testResult) {
    //Can get testResult.FirstName
    this.firstName = testResult.FirstName;
  
    this.dataService.writeResult(testResult.FirstName);
  }
  </code></pre>
  
  <p>But the problem is that an error comes out saying that .writeResult() is not known. I think it's because the life of the Component has ended?</p>
  
  <p>I just want to ask for help on how I would get the testResult object and its properties outside function()?</p>