每次访问 View 时都重新初始化 Controller - Ionic Framework
问题描述:
我的应用中有两个视图,每个视图都分配了两个控制器.每次导航到特定视图时,我都需要重新初始化控制器.
Hi i'm having two views in my app with two controllers assigned to each. Here i need to reinitialize the controller every time when ever i navigate to particular view.
角度脚本:
.state('app.pnrlist', {
url: "/pnrlist",
views: {
'menuContent': {
templateUrl: "templates/test.html",
controller: "testControl",
reload: true
}
},
reload:true
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller:"homeControl",
reload:true
}
},
reload:true
})
HTML 内容
<ion-content>
<ion-list>
<ion-item nav-clear menu-close href="#/app/home">
Home
</ion-item>
<ion-item nav-clear menu-close href="#/app/pnrlist">
PNR List
</ion-item>
</ion-list>
</ion-content>
我尝试在堆栈上实现许多解决方案,但没有一个对我有帮助.尝试过的解决方案 1/尝试过的解决方案 2
I have tried to implement many solutions on stack but none helped me. Solution Tried 1 / Solution Tried 2
答
如果是 View 没有更新的问题,禁用缓存可能会有帮助
If its a matter of the View not updating, disabling the Cache may help
即
.state('app.home', {
url: "/home",
cache: false,
默认情况下,视图会被缓存以提高性能.您还可以通过 'cache-view' 属性禁用缓存
As by default, views are cached to improve performance. You can also disable the cache via the 'cache-view' attribute
<ion-view cache-view="false" view-title="My Title!">
...
</ion-view>