My objective: 订阅具有Angular区域的观察者 . 我使用背景地理定位插件在应用关闭时获取设备位置 . 根据位置,我想停止用户之前已启动的计时器 . 我处理在我的组件中停止的计时器 .
geolocation.service.ts
startBackTracking(destLat, destLng)
{
return this.backgGeolocation.configure(config)
.map((pos) => {
this.zone.run(() => {
this.lat = pos.latitude;
this.lng = pos.longitude;
let isOnSite = this.isAtSite(this.lat, this.lng, destLat, destLng);
return isOnSite;
});
});
}
handler.component.ts
this.geolocationService.startBackTracking(this.destLat, this.destLng)
.subscribe((res) => {
//stop timer depending on res
}
My problem: 当应用关闭时,我知道区域任务将会运行 . 但是当区域在不同的上下文中运行时,我的订阅代码会在应用程序关闭时执行吗?和/或是否有更好的方法来处理Angular区域的订阅?