I'm using a third party JS I'm calling from Angular:
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;
}
}
}
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.
I also tried running a service inside the function so that I can pass the data to a service after onTestCompleted():
constructor(private dataService: DataService) {}
function onTestCompleted(testResult) {
//Can get testResult.FirstName
this.firstName = testResult.FirstName;
this.dataService.writeResult(testResult.FirstName);
}
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?
I just want to ask for help on how I would get the testResult object and its properties outside function()?