private nodes = [];
constructor(private nodeService: NodeService) {}
this.nodeService.getNodes('APIUrl')
.subscribe((data) => {
this.nodes.push(data);
});
console.log(this.nodes)
這是我獲取數據的組件。Typescript/Angular 2
getNodes(url) {
return this.http.get(url)
.map((data) => data.json())
}
這是我的服務,而我得到我的數據並將其映射
然而,當我在CONSOLE.LOG我的組件(this.nodes)這是我的結果:
[1: Array[0]]
And it is possible to see the structure of my data as shown here
所以我的問題是當我的console.log(this.nodes [0])在我的組件中,我得到了未定義。我似乎無法訪問我的數據,因爲我需要。有什麼想法嗎?
代碼是異步的,看看答案l鏈接到 –
Okey謝謝! – Artulo