首页 > 解决方案 > 如何在Angular中重复请求?

问题描述

我有带有方法的组件:load():

load() {
   this.simpleDictService
      .get(
         this.dictCode,
         this.pagination.from,
         this.pagination.to,
         this.showDeleted
      )
      .subscribe((response: IResponseDict) => { this.res = response; });
   }

每当我在输入字段中输入消息时都会调用此方法。

结果,我从服务器获得了响应数据:

this.res = response; 

还有一个导出到 Excel 按钮。单击它后,我想使用附加参数重复发送到服务器的先前请求。我如何在 Angular 中做到这一点?

实际上,我可以将以前的 URL 存储在存储中,然后对其进行修改。

标签: angularangular8

解决方案


您现在可以通过以下方式尝试

    private subscriptionFileUpload;

    load() {
     if (this.subscriptionFileUpload) {
       this.subscriptionFileUpload.unsubscribe();
     }
     this.subscriptionFileUpload = this.simpleDictService
          .get(
            this.dictCode,
            this.pagination.from,
            this.pagination.to,
            this.showDeleted
          )
          .subscribe((response: IResponseDict) => { this.res = response; });
    }

当您需要时调用 load 方法,或者您可以释放到.subscribe


推荐阅读