我有一个运行正常的进度条。我想在客户端向服务器发送消息并等待响应时显示它。我为此编写的代码是
public getInformation(info:Info):any {
this.loaderService.show(); //this shows progress bar
return this.http.post(this.GET_INFO_URL,info,httpOptions)
.pipe(tap(response => {
return response;
})
,catchError(this.handleError)
,finalize(()=> this.loaderService.hide())); //hide progress bar
}
上面的代码工作正常,但我不确定这是否是正确的设计esp。因为响应是异步的。在Angular中,这种可接受的方法是在一个线程中显示一个组件,而在另一个线程中隐藏它吗?有没有更好,更安全的方法?