[英]Angular2 HTTP POST using observables subscribe shows data as 'undefined'
[英]Angular2 map and subscribe
我正在開發一個angular4應用程序。 我的Component.ts看起來像:
ngOnInit() {
this.http.get('http://localhost:4000/data/').subscribe(data => this.temp = data);
// this.temp1 = JSON.parse(this.temp)
console.log(this.temp)
}
在控制台我得到“未定義”的this.temp
這樣寫你的console.log
this.http.get('http://localhost:4000/data/').subscribe(data => {this.temp = data; console.log(this.temp)});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.