Hi!
I am a bit stuck with Angular HttpClient.
I am fetching data from an API via a service.
//my service
export class CoronaService {
constructor(
private http: HttpClient
) { }
getAll() {
return this.http
.get('https://covid19.mathdro.id/api')
}
}
My component looks like this
export class AppComponent implements OnInit {
corona = [];
constructor(
private coronaService: CoronaService
) {}
ngOnInit() {
this.coronaService.getAll().subscribe((response: any[]) => {
this.corona = response;
}, err => {
console.log('Error', err);
});
}
}
My view where the problem is
<p> {{ corona }} </p>
I get this as out[object Object]
If I do this
<p> {{ corona | json }} </p>
I get the json data.
If I try to access a property I get an error cannot get property x of undefined.
I tried to figure out but in vain. Can you tell me where error is?
Latest comments (4)
Hi @aditya Thebe, Katie Nelson,
If you go to the API you'll have this
I want to display confirmed, deaths, revovered values.
I have already resolved my issue.
Thank you!
Which property are you trying to access ?
Which properties have you defined?
Your request returns JSON and you can see that. What are you looking for? Stringify or parse?