我正在Angular 2上工作,而我的後端是NodeJs。我只是按照教程連接到服務器,但它不起作用。這是我在app.component.ts代碼:角2無法連接到服務器
this.http.get<Contributor[]>('http://localhost:3000/message/').subscribe(data => {
// data is now an instance of type ItemsResponse, so you can do this:
this.contributors = data;
console.log(this.contributors);
});
console.log(this.contributors);
第一「this.contributors」顯示的數據很好,但第二個是不確定的。有什麼可以幫助我嗎?非常感謝!
謝謝很多爲您的幫助!無論如何處理它,或只是等待它?非常感謝! –
因爲http是異步的,所以你不得不等待它 –
但是我的表讀取了貢獻者並返回undefined。無論如何,讓所有其他的東西暫停,只是等待http?或者是否有任何同步呼叫?謝謝! –