我正在使用 Ionic 开发一个应用程序,但缓存未按预期工作。
每次我从 root.home.notifs
切换到 root.home.chats
时,chats
View 都会刷新(其 Controller 会重新初始化)。
我有 2 个标签:
<ion-footer-bar>
<ion-tabs class="tab-bottom tabs-striped">
<ion-tab icon="ion-ios-chatboxes-outline" ui-sref="root.home.chats">
</ion-tab>
<ion-tab icon="ion-ios-heart-outline" ui-sref="root.home.notifs">
</ion-tab>
</ion-tabs>
</ion-footer-bar>
这些状态(我的 Controller 是空的):
.state('root.home', {
abstract: true,
cache : true,
url: '/home',
templateUrl: 'components/home/templates/home.html'
})
.state('root.home.chats', {
url: '/chats',
cache : true,
controller: 'ChatCtrl',
templateUrl: 'components/home/templates/home.chats.html'
})
.state('root.home.notifs', {
url: '/notifs',
cache : true,
controller: 'NotifCtrl',
templateUrl: 'components/home/templates/home.notifs.html'
})
每个 View 都有cache-view="true"
,我已经通过这种方式配置了缓存$ionicConfigProvider.views.maxCache(100)
注意:我注意到此错误取决于我首先导航到哪个状态。有一个调用 $state.$go('root.home.notifs')
的身份验证系统。更改此设置会更改正确缓存的 View
有什么解决这个问题的建议吗?
最佳答案
尝试使用它来缓存前向 View $ionicConfigProvider.views.forwardCache(true);
关于caching - ionic 缓存不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38475405/