我如何在Ionic 2中订阅页面更改?我只想全局记录页面名称/标题。是否有可以订阅的事件?
我如何在Ionic 2中订阅页面更改?我只想全局记录页面名称/标题。是否有可以订阅的事件?
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 中订阅
this.routeNamesService.name.subscribe(name => this.routeName = name);
this.routeNamesService.setRouteName("Settings");
(或)在 app.component.ts 中
@ViewChild(Nav) nav: Nav;
ngAfterViewInit() {
this.nav.viewDidEnter.subscribe((data) => {
console.log(data);
});
}