2017-03-21 3 views
0

私は、2ページを含むIonic 2のアプリを持っています。ホームページのボタンをクリックすると、現在の位置とその周辺の場所を特定するマップがあるページに送られます。すべての場所が表示されますが、ホームページに戻ってボタンを再度クリックすると、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'); 
    } 

    }); 

}); 
+0

ionViewWillEnterで機能を試しましたか? – JoeriShoeby

答えて

0

経路で観察を使用してみてください。

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

+0

ありがとう!あなたはこのコードを私に説明してください、私はあなたのコードに私のコードを変更する方法を私は角度に新しいですか? – mehdi

+0

あなたのルータに入れておく必要があります。どうしたらいいのか分からない場合は、このチュートリアルを実行してください。https://angular.io/docs/ts/latest/tutorial/ –

+0

私もこれはあなたの質問の範囲外です。あなたにそれらを行う方法を教えてください。しかし、。ここ数回は確かに答えられています。 –

関連する問題