private nodes = [];
constructor(private nodeService: NodeService) {}
this.nodeService.getNodes('APIUrl')
.subscribe((data) => {
this.nodes.push(data);
});
console.log(this.nodes)
これはデータを取得する私のコンポーネントです。入力文字/角2
[1: Array[0]]
And it is possible to see the structure of my data as shown here:
getNodes(url) {
return this.http.get(url)
.map((data) => data.json())
}
は、これは私が私のコンポーネントで(this.nodes)をCONSOLE.LOGしかし、これは私の結果であり、私は私のデータを取得し、
それをマッピングし、私のサービスであり、
私の問題は、私のコンポーネントのconsole.log(this.nodes [0])が未定義のときです。私は必要なときに自分のデータにアクセスできないようです。何かご意見は?
コードは非同期です。私は –
にリンクしている回答を見てください。 – Artulo