控制台日志在这里未定义
this.http.get(this.rootURL + "/Report/"+id)
.toPromise().then(res => this.report = res as Report);
console.log(this.report);
}
这里控制台记录数据
this.http.get(this.rootURL + "/Report/"+id)
.toPromise().then(res => console.log(res));
console.log(this.report);
}
如何将结果分配给Result Object
在then
的promise中记录您的数据:
this.http.get(this.rootURL + "/Report/"+id)
.toPromise()
.then(res => {
// Promise gets fulfilled and its response can be assigned
this.report = res as Report;
console.log(this.report);
// Perform other actions
// ...
})
.catch(reason => {
// Something went wrong, your promise gets rejected
console.log(reason);
});
你在等待吗?
你应该做这样的事情:
const main = async () => {
await this.http.get(this.rootURL + "/Report/"+id).toPromise().then(data => {
console.log(data);
})
}