angular - 如何在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 存储在存储中,然后对其进行修改。
解决方案
您现在可以通过以下方式尝试
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
推荐阅读
- arrays - 为什么每当我单独使用“if”语句以及在“if”中使用“if”时值会发生变化?
- c# - 关于在 Protobuf-net 中实现 VARIANT
- html - 嗨,我在 flexbox 中定位有问题
- reactjs - (React & Mobx & Leaflet)等待然后没有按我预期的那样工作
- javascript - 猫鼬填充返回未定义
- python - 在 Python 中使用 for 循环对多个 DataFrame 进行操作
- reactjs - 如何将 href 传递给 nextjs 中的 onClick 函数?
- python - 将字符串传递给 subprocess.run 似乎将其括在单引号中否定通配符搜索?
- c - 为什么 __builtin_return_address 在 Clang 中崩溃?
- python - Python 错误消息,包括“ImportError: cannot import name 'string_int_label_map_pb2'”