等待服务响应,然后继续进行??

问题描述 投票:0回答:1
基本上是希望当一个组件被调用时,它应该等到服务返回数据。我有一个组件在加载时调用一个服务。在服务中,我有一个具有HTTP调用的函数,然后它给响应提供了调用该服务的另一个函数,因此当我简单地执行该组件时,它给出的响应为时已晚。我想等到服务返回响应数据。

我尝试使用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); } ); }```

基本上是希望当一个组件被调用时,它应该等到服务返回数据。我有一个组件在加载时调用一个服务。在服务中,我有一个函数...
node.js angular http angular6 angular7
1个回答
0
投票
执行类似操作:
© www.soinside.com 2019 - 2024. All rights reserved.