private nodes = [];
constructor(private nodeService: NodeService) {}
this.nodeService.fetchNodes('APIEndpoint')
.subscribe((data) => {
this.nodes.push(data);
});
console.log(this.nodes)
This is the component responsible for fetching and storing data.
fetchNodes(url) {
return this.http.get(url)
.map((res) => res.json())
}
This is my service where I retrieve and structure the data.
However, when I check the contents of `this.nodes` in my component using console.log, the output displays as follows:
[1: Array[0]]
You can view the structure of the data here.
My issue arises when trying to access the first element of `this.nodes` by console.logging `this.nodes[0]`. The result returned is 'undefined'. What could be causing this problem?