I am encountering an issue when trying to retrieve the value of the existResults variable within a function that is called before the one where the variable is declared. The value returned is undefined.
public existResults: any;
ngOnInit(): void {
this._activatedRoute.params.subscribe(params => {
this.patientId = params['patient'];
const testId = params['test'];
this.getTestResults();
this.getProccessesByTest(testId);
});
}
getTestResults(id:any) {
this._testsService.getTestResults(this.token, id, this.patientId).subscribe(
response => {
this.results = response.data;
if (this.results.length == 0) {
this.existResults = false;
}else if(this.results.length > 0) {
this.existResults = true;
}
console.log(this.existResults); //output true
},
error => {
console.log(error);
}
);
}
getProccessesByTest() {
console.log(this.existResults); //output undefined
}