1

我的目标:订阅具有 Angular 区域的可观察对象。当应用程序关闭时,我使用后台地理定位插件来获取设备位置。并且根据位置,我想停止用户之前启动的计时器。我处理在我的组件中停止的计时器。

地理位置.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
    }

我的问题:当应用程序关闭时,我知道区域任务将运行。但是由于该区域在不同的上下文中运行,我的订阅代码会在应用程序关闭时执行吗?和/或是否有更好的方法来处理对 Angular 区域的订阅?

4

0 回答 0