我尝试使用setTimeout
并做出承诺,但仍然需要时间和功能才能提前执行。
设置超时
setTimeout(() => {
if (this.persistenceService.get('base64') != '' || this.persistenceService.get('base64') != null || this.persistenceService.get('base64') != undefined) {
this.selectedFileData = this.persistenceService.get('base64');
this.SpinnerStart = false;
} else {
setTimeout(() => {
this.selectedFileData = this.persistenceService.get('base64');
this.SpinnerStart = false;
}, 10000);
}
}, 10000);
我想加载组件加载器,直到服务给出响应为止。这里的服务代码:
this.HttpClients.post(APIcall, Data, config).subscribe(
async (response: any) => {
if (response.status == 200) {
this.json_data = response.data;
this.invoice_pdf(this.json_data, types, '', types, this.Invoice_Number);
// $template_id
}
},
error => {
console.log('Error', error);
}
);
}```
基本上是希望当一个组件被调用时,它应该等到服务返回数据。我有一个组件在加载时调用一个服务。在服务中,我有一个函数...