如何tmp记录接收到的数据?通过returnfrom函数,返回了一个对象promise,但是在函数本身tmp是不可见的
tmp: string;
constructor(private http: Http) {
this.tmp = "load";
this.GetUsers();
}
ngOnInit() {
setTimeout(console.log("Hello"), 2000);
}
GetUsers() {
this.http.get('http://localhost:1337/api/users')
.toPromise()
.then(function(response) {
this.tmp = "success"
})
.catch(this.handleError);
加上它不起作用setTimeout。也就是说,它只工作一次,仅此而已。
如果 Angular 的版本是 4.3+ 然后使用 HttpClient