как мне в tmp записать полученные данные? Через return из функции возвращается объект 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. То есть он срабатывает лишь раз и все.
async– Igor Golovin Jul 19 '17 at 22:21