angular - Angular 4:一个订阅,两个 Http 调用
问题描述
我正在尝试以一种非常标准的方式将数据发布到服务器,我之前可能已经做过一百万次了,但是在这种特殊情况下,正在进行两个 http 调用。谁能帮助解释为什么会发生这种情况?
我将 Angular 4.2.4 与 Rxjs 5.4.3 一起使用,并使用HttpClient
.
下面是相关的组件代码,使用 UI 中的事件处理程序调用。
this.visitsService
.addMeasuredWeight(this.visit.Id, this.kid.Id, weight)
.subscribe(result =>
this.kid.Weights.push(MeasuredWeightDto.ToMeasuredWeight(result))
);
这是服务代码
public addMeasuredWeight(
visitId: string,
personId: string,
measuredWeight: MeasuredWeight
): Observable<MeasuredWeightDto> {
let url: string = `${this.getBaseUrl()}/${visitId}/persons/${personId}/weights`;
return this.http.post<MeasuredWeightDto>(
url,
MeasuredWeightDto.FromMeasuredWeight(measuredWeight)
);
}
我已经通过调试器确认这些方法只被调用一次,但是在 Chrome DevTools 网络选项卡中,创建了两个 http 帖子,并且订阅结果处理程序确实运行了两次。下面是来自 DevTools 的屏幕截图,显示了多个帖子。
任何帮助确定为什么在此处进行多次调用的任何帮助都将不胜感激。如果需要任何其他信息,请告诉我。提前致谢。
解决方案
推荐阅读
- javascript - 如何找到在 Inspector>Network(网络抓取)上执行的特定事件?
- nuxt.js - SSR 渲染和客户端交互
- reactjs - 在 BackHandler 中处理异步反应原生和反应导航 v.4
- python - 十进制转二进制不存储余数
- file-io - 在 Xamarin iOS 上以奇怪的顺序读取文件中的项目
- python - TF Keras ValueError: Shapes (None, 3, 3) 和 (None, 3) 不兼容
- acumatica - 发布包含 Smartsheet SDK 参考的自定义时出现验证错误
- go - 去 mod 更新依赖并离开本地
- php - EasyAdmin 3 - 在仪表板中模拟用户
- javascript - 如何在javascript中重新加载时将活动类保存到localstorage并保留