重新进入页面后,承诺不起作用

时间:2017-03-21 16:17:29

标签: angular typescript ionic2 promise

我有一个Ionic 2的应用程序包含2页。当我点击主页上的一个按钮时,它会将我发送到一个页面,在该页面中我们有一张地图可以找到当前位置和附近位置。显示所有位置,但当我返回主页并重新单击按钮时,第二页中的地图仅显示当前位置而不显示附近位置。 这是初始化第二页的代码:

ionViewDidLoad(){

this.platform.ready().then(() => {
  let mapLoaded = this.maps.init(this.mapElement.nativeElement, this.pleaseConnect.nativeElement);
  let locationsLoaded = this.locations.load();

  Promise.all([
    mapLoaded,
    locationsLoaded
  ]).then((result) => {
    let locations = result[1];

    for(let location of locations){
      this.maps.addMarker(location.latitude, location.longitude,'http://maps.google.com/mapfiles/ms/icons/blue-dot.png');
    }

  });

});

1 个答案:

答案 0 :(得分:0)

尝试使用带路径的observable;

constructor(router:Router) {
  router.events.subscribe(event:Event => {
    if(event instanceof NavigationStart) {
    }
    // NavigationEnd
    // NavigationCancel
    // NavigationError
    // RoutesRecognized
  });
}

你也可以尝试阅读这篇文章;可能有帮助。 https://angular-2-training-book.rangle.io/handout/observables/observables_array_operations.html

相关问题