I have been struggling in accessing my API response, which looks like this:
{
"products": [
{
"creationDate": "2018-09-18T23:44:38.062Z",
"_id": "5ba18dea6d29622f1c539674",
"name": "Sample 1",
"description": "some description goes here for sample product",
"count": 3,
"__v": 0
},
{
"creationDate": "2018-09-18T23:44:38.062Z",
"_id": "5ba18e756d29622f1c539675",
"name": "Sample 3",
"description": "some description goes here for sample product",
"count": 3,
"__v": 0
}
]
}
This is retrieved by the following method call in my Service:
getAll(){
return this.http.get('https://jsonplaceholder.typicode.com/posts')
.map(response => response);
}
Here is where I call it in my component:
ngOnInit() {
this.newService.getAll().subscribe(data =>
{
this.Repdata = data.json();
this.Repdata = Array.of(this.Repdata);
console.log(data)
}
)}
And here is where it is displayed in my Component html:
<p *ngFor="let key of Repdata">
<span>
sample |{{key.name}}
</span>
</p>
Nothing is being displayed in my HTML output. What am I doing wrong?
*ngFor="let key of Repdata.products".