Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 如何在Ionic 2中自动检测视图更改_Ionic Framework_Ionic2 - Fatal编程技术网

Ionic framework 如何在Ionic 2中自动检测视图更改

Ionic framework 如何在Ionic 2中自动检测视图更改,ionic-framework,ionic2,Ionic Framework,Ionic2,我有一个用例,需要检测显示给用户的当前视图,以便向Google Analytics报告。我知道,但那不是我想要的 我想知道的是,是否有一种方法可以“钩住”爱奥尼亚的导航系统,以便在用户每次导航应用程序时订阅导航事件并获取路线或视图对象。由于爱奥尼亚2没有使用Angular2的路由器,因此我无法使用以下各项: export class AppComponent { private currentRoute:string; constructor(_router:Router,

我有一个用例,需要检测显示给用户的当前视图,以便向Google Analytics报告。我知道,但那不是我想要的

我想知道的是,是否有一种方法可以“钩住”爱奥尼亚的导航系统,以便在用户每次导航应用程序时订阅导航事件并获取路线或视图对象。由于爱奥尼亚2没有使用Angular2的
路由器
,因此我无法使用以下各项:

export class AppComponent {
    private currentRoute:string;
    constructor(_router:Router,
                _location:Location) {
        _router.events.subscribe((event:Event) => {
            if (event instanceof NavigationEnd) {
                // When the route is '/', location.path actually returns ''.
                let newRoute = this._location.path() || '/';
                // If the route has changed, send the new route to analytics.
            if (this.currentRoute != newRoute) {
                ga('send', 'pageview', newRoute);
                this.currentRoute = newRoute;
            }
        }
        });
    }
}
有人知道如何订阅爱奥尼亚2应用程序中的导航更改吗

我的当前设置截至写入时间为:

Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.48

您可以订阅中描述的
App
生命周期事件

更具体地说,您需要从
ionic angular
注入
App
,然后在需要的地方添加如下代码:

this.app.viewWillEnter.subscribe(viewCtrl => {
   console.log('Entering new view')
   console.log(viewCtrl)
})

订阅根用户的NavController事件,如“IonViewDiCenter”等。有关更多信息,请参阅NavController生命周期事件:正如我在问题中提到的,我知道这些生命周期事件,它们不适合我的用例。我想在我的提供商中订阅导航事件,这样我就可以在一个地方维护代码。通过使用生命周期事件,我被迫在每个页面上维护事件处理程序。如果您订阅根NavController,请提供一个订阅根NavController的示例?我的应用程序是使用tabs starter设置的