2017-04-08 5 views
1

Ionic 2のページ変更を登録するにはどうすればよいですか?私はちょうど世界のページ名/タイトルを記録したいと思う。私が購読できるイベントはありますか?Ionic 2 Page Change Subscription

+0

を得ることができます。.. –

+0

これをグローバルに行うので、すべてのファイルに触れる必要はありません。 – mark

+0

アプリケーションのコンポーネントroot navcontrollersのイベントを聞く必要があります。 – JoeriShoeby

答えて

0

あなたが火

this.routeNamesService.setRouteName("Settings"); 

(または)内のコンポーネントにして入力したとき

this.routeNamesService.name.subscribe(name => this.routeName = name); 

に加入app.component.ts で

import {Injectable} from '@angular/core'; 
import {Subject} from 'rxjs/Rx'; 

@Injectable() 
export class RouteNamesService{ 
    constructor(){ 
    } 
    public name = new Subject(); 

    setRouteName(name){ 
     this.name.next(name); 
    } 
} 

サービスを作成しますapp.component.ts

私はしたいと思います3210
@ViewChild(Nav) nav: Nav; 

    ngAfterViewInit() { 
    this.nav.viewDidEnter.subscribe((data) => { 
     console.log(data); 

    }); 

    } 

データに、あなたがこのような何かのために[イベント](http://ionicframework.com/docs/api/util/Events/)を使用することができコンポーネント名