2017-04-08 3 views
1

이오닉 2 페이지 변경을 어떻게 구독 할 수 있습니까? 나는 페이지 이름/제목을 세계적으로 기록하고 싶다. 구독 할 수있는 이벤트가 있습니까?이오니아 2 페이지 변경 서브 스크립 션

+0

[이벤트] (http://ionicframework.com/docs/api/util/Events/)이 같은 뭔가 ... –

+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

@ViewChild(Nav) nav: Nav; 

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

    }); 

    } 

당신이 사용할 수
관련 문제