简体   繁体   English

Angular2地图并订阅

[英]Angular2 map and subscribe

I am developing an angular4 application. 我正在开发一个angular4应用程序。 My Component.ts looks like: 我的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)

}

On the console I am getting 'undefined' for 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM