export interface Relation{
name: string;
address: string;
dob: number;
}
The JSON response I received is as follows:
[ {"name":"John", "address":"xyz", "dob":"2000-01-10"},
{"name":"Jamie", "address":"abc", "dob":"1990-01-10"}
]
The issue seems to be with mapping the response to the Interface.
relations:Relation []=[];
getRelations() : Observable<Relation[]> {
return this.http.get('url for json response').map(this.extractData).do(data=>console.log("Get all responses"+JSON.stringify(data))).catch(error => this.errorMessage = error);
}
extractData( response : Response){
let body = response.json();
console.log("Body", body);
return body.data;
}
When calling the getRelations method, it returns nothing.
ngOnInit(){
this.getRelations().subscribe(relations=> relations, error=> this.errorMessage=<any>error);
}
Trying to display the data in HTML as table rows does not show anything. This indicates a problem either with initializing the Relation[] array or missing some key information.
Displaying the data using ngFor loop also does not work.
<tr *ngFor="let row of relations">
<td> {{row.name}} </td>
<td> {{row.address}} </td>
<td> {{row.dob}} </td>
</tr>