Hello Everybody,
I’m working through a Angular 4 tutorial using HttpClient and having a bit of a problem with displaying data from an array.
The data is from https://jsonplaceholder.typicode.com/posts
I know I can run it through the *ngFor direcitive and this works but I like to know how to go about
select individulal data from the array without receiving an error message: ERROR TypeError: Cannot read property ‘0’ of undefined.
any help you can provide would be greatly appreciated.
R
example:
{{returnedArray[0][‘body’]}} or {{returnedArray[1][‘body’]}}
component
this._getService.getDetailsMethod().subscribe(
data => { this.returnedArray = data;
console.log('returnedArray: ', this.returnedArray[0].userId);
},
services
getDetailsMethod(){
return this._httpC.get<any>(this.userListingURL);
}
PHP
php
if($data) {
echo json_encode($data);
}