I am trying to convert a json response into an array in angular 2. The following is the code i have used,
.ts file
response;
resp;
constructor(private http:Http) {
}
get()
{
this.http.get("http://localhost:3000/items")
.map(res=>res.json())
.subscribe(data=>this.response = JSON.stringify(data))
this.resp = JSON.parse(this.response);
}
component.html
{{response}}
<ul>
<li *ngFor="let k of resp">{{k}}</li>
</ul>
</div>
Although the {{response}} simply results in the whole json content getting displayed, i am unable to iterate through the response retrieved in resp despite using JSON.parse().
How can I convert the response to an array and access the individual properties ?