【发布时间】:2017-02-01 20:49:12
【问题描述】:
我对 Angular 2 中两个单独的 observable 的两个顺序订阅有疑问。 我正在尝试:
- 从坐标获取位置
- 将此位置附加到我的 json 中
- 发送json到服务器
我认为我这样做的方式是错误的:
this._locationService.geocode(this.location.latitude, this.location.longitude).
subscribe(position => {
this.location.city = this.findAddressPart(position, "locality", "long");
this.location.country = this.findAddressPart(position, "country", "long");
this._locationService.updateLocation(this.location)
.subscribe(
location => {
this.location = location;
this.submitted = true;
this.submitting = false;
}
);
});
这样我的 DOM 在我实际获取位置后仅更新 5-10 秒。
【问题讨论】:
-
您是否尝试在角度区域中运行它?使用 this.zone.run( () => {}) 你应该只在区域内运行位置分配
-
它是如何工作的?
-
请参考这篇文章:joshmorony.com/…
-
实际问题是什么?目前没有发生的事情应该是什么?
-
谢谢@galvan!问题是我在第二个订阅中的代码在角度之外工作并且没有运行更改检测。我在 zone.run 块中运行它,它现在可以正常工作了!
标签: angular angular2-observables