简体   繁体   中英

Angular2 map and subscribe

I am developing an angular4 application. My Component.ts looks like:

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

这样写你的console.log

this.http.get('http://localhost:4000/data/').subscribe(data => {this.temp = data; console.log(this.temp)});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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