[英]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.