UPDATE How I accomplished this task is detailed below (click on the link to view my answer):
I am currently working on developing an APIService in Angular 7. My approach involves using subscribe to add data to an array that seems inaccessible through another service.
This is the method within the API service:
getResponse(url):Observable<any> {
return this.http.post(url, '', {responseType: 'text'});
}
getAll() {
this.getResponse(this.todayApiUrl).subscribe(
(response) => {
this.data.push(response);
});
return this.data;
}
Below is how I am attempting to invoke it in the secondary service:
export class AdsHealthService {
today = this.callResponseApiService.getAll();
constructor(private callResponseApiService: CallResponseApiService) { }
getHealthValue(interval, type) {
let obj = this.today;
console.log(obj);
}
}
The image attached depicts what I see when I console.log()
the response. While it appears to be an array, trying to access the first element results in an undefined
message. What could be the mistake in my approach?
https://i.sstatic.net/NR3Ob.png