0

知道我在这里做错了什么。我有一个角度微调器,显示有 http 请求,当他们完成时微调器被隐藏

我在方法中使用 concatMap 检查是否在本地存储中找到数据,如果找到则从那里获取它,如果没有则通过 http 获取它(获取后我将其添加到本地存储)该方法如下所示:

return this.localDBService.get(this.selectedLog['Id']).pipe(concatMap(storedLog => {
      if (storedLog) {
        return of(JSON.parse(storedLog['log']));;
      } else {
        return this.metadataService.getLogBody(this.connection.instanceUrl, this.connection.accessToken,
          this.connection.id, this.selectedLog['Id']).pipe(concatMap(log => {
            this.localDBService.add(log, this.selectedLog['Id']).pipe(take(1)).subscribe(() => { });;
            return of(log);
          }));
      }
    }));

微调器拦截器是这样的:

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        if (!req.url.includes('items?query')
            && !req.url.includes('checkconnection')
            && !req.url.includes('assets')) {
            this.spinnerService.show();
            this.totalRequests++;
            console.log('totalRequests: ', this.totalRequests);
            return next.handle(req)
                .pipe(
                    finalize(() => {
                    this.completedRequests++;
                    console.log('completedRequests: ', this.completedRequests);
                    if (this.completedRequests === this.totalRequests) {
                        this.spinnerService.hide();
                        this.completedRequests = 0;
                        this.totalRequests = 0;
                    }
                })
                );
        } else {
            return next.handle(req);
        }
    }

我在这里做错了什么?不调用 finalize 并且不隐藏微调器。似乎可观察的永远不会结束......我在第一个 concatMap 中有另一个 concatMap,这是导致问题的原因吗?

4

0 回答 0