I'm currently working on converting a JSON response into an array within Angular 2. Below is the code I have implemented:
.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>
Even though {{response}} displays the entire JSON content, I'm struggling to iterate through the response retrieved in resp even after using JSON.parse().
Any suggestions on how to successfully convert the response into an array and access the individual properties?