每次页面更改时,我都想执行一些代码。
我可以为每个页面添加一个ngOnDestroy
方法。看来我可以使用 Ionic 2 页面生命周期钩子(例如ionViewDidUnload
)来获得完全相同的效果,但我没有费心去测试它。我宁愿在主应用程序类中添加一个方法。
我看到您可以订阅 Angular 2路由器事件。我如何翻译它以在 Ionic 2 中使用?我import { Router } from '@angular/router;
首先遇到了一个错误:
TypeScript error: <path>/node_modules/@angular/router/src/common_router_providers.d.ts(9,55): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'NgModuleFactoryLoader'.
TypeScript error: <path>/node_modules/@angular/router/src/router.d.ts(14,39): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'NgModuleFactoryLoader'.
TypeScript error: <path>/node_modules/@angular/router/src/router_module.d.ts(9,10): Error TS2305: Module '"<path>/node_modules/@angular/core/index"' has no exported member 'ModuleWithProviders'.
网络包配置
var path = require('path');
module.exports = {
entry: [
path.normalize('es6-shim/es6-shim.min'),
'reflect-metadata',
path.normalize('zone.js/dist/zone'),
path.resolve('app/app.ts')
],
output: {
path: path.resolve('www/build/js'),
filename: 'app.bundle.js',
pathinfo: false // show module paths in the bundle, handy for debugging
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'awesome-typescript',
query: {
doTypeCheck: true,
resolveGlobs: false,
externals: ['typings/browser.d.ts']
},
include: path.resolve('app'),
exclude: /node_modules/
}
],
noParse: [
/es6-shim/,
/reflect-metadata/,
/zone\.js(\/|\\)dist(\/|\\)zone/
]
},
resolve: {
alias: {
'angular2': path.resolve('node_modules/angular2')
},
extensions: ["", ".js", ".ts"]
}
};
无论如何,如果有办法使用ionic-angular的Nav
or服务,这对我来说更有意义。NavController
有没有办法做到这一点?