Angular2地图和订阅

时间:2017-11-11 09:07:44

标签: json angular http rxjs

我正在开发一个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

进行“未定义”

1 个答案:

答案 0 :(得分:1)

像这样写

你的console.log
this.http.get('http://localhost:4000/data/').subscribe(data => {this.temp = data; console.log(this.temp)});
相关问题