2017-11-10 109 views

回答

4

第一部分啓動異步操作,並且console.log部分被立即運行,異步操作完成之前。

您必須延遲引用this.data,直到您知道異步操作已完成。

你可以做到這一點通過將console.log的訂閱處理程序中:

this.postServices.getData().subscribe((res)=>{ 
    this.data = res; 
    console.log(this.data); 
})