【发布时间】:2019-01-22 10:58:32
【问题描述】:
当我运行下面的代码时,checkCard 函数在 getTimecard 函数完成之前运行。
getTimecard() {
this._service.getTimecard().subscribe(
data => {
this.sending = true;
this.timecards = data;
},
err => {
this.sending = false;
console.error(err);
},
() => {
this.sending = false;
}
);
}
checkCards() {
console.log('timecards', this.timecards);
//code dependent on timecard data
}
async onSubmit() {
await this.getTimecard();
this.checkCards();
}
为什么 checkOverlap 不等待 getTimecard 返回它的数据?
【问题讨论】:
-
getTimecard不返回任何等待。
标签: javascript typescript async-await angular5