export interface Relation{
name: string;
address: string;
dob: number;
}
My JSON response is
[ {"name":"John", "address":"xyz", "dob":"2000-01-10"},
{"name":"Jamie", "address":"abc", "dob":"1990-01-10"}
]
This is not mapping the response to the Interface! That;s the problem.
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;
}
i call the get Relations but get nothing !
ngOnInit(){
this.getRelations().subscribe(relations=> relations, error=> this.errorMessage=<any>error);
}
When i try to retrieve the data in HTML as a table row i get nothing! Which means either the Relation[] array is not initialized itself or i'm missing something here.
when i do this i get nothing !
<tr *ngFor="let row of relations">
<td> row.name</td>
<td> row.address</td>
<td> row.dob</td>
</tr>
relationsto your response fromgetRelations()? Edit: Nevermind, I see you just added it..subscribe(relations => this.relations = relations)