离子缓存无效

4
我正在使用Ionic开发一个应用,但是缓存没有按照预期工作。每当我从root.home.notifs切换到root.home.chats时,chats视图都会刷新(它的控制器被重新初始化)。
我有两个选项卡:
  <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>

这些状态(我的控制器为空):

.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'
})

每个视图都有cache-view="true",我这样配置缓存:$ionicConfigProvider.views.maxCache(100) 注意:我注意到这个错误取决于我首先导航到哪个状态。有一个身份验证系统会调用$state.$go('root.home.notifs')。更改这个将更改正确缓存的视图。
是否有什么建议可以解决这个问题?
3个回答

3
尝试使用以下代码来缓存前向视图:$ionicConfigProvider.views.forwardCache(true);

1

试试这个:

.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'
})

完成了,但我仍然有同样的问题。 - Devid Farinelli
我认为问题在于使用了cache-view="true",请改为cache-view="false"。 - Vikram Biwal
1
cache-view="true" 用于告诉 Ionic 缓存一个视图,这正是我想要实现的。无论如何,我尝试了 cache-view="false",但它并没有起作用。 - Devid Farinelli
抱歉,是我的错误,我指的是你的拼写有误,应该是 chache-view="true",true 是正确的。 - Vikram Biwal

-1

在编程中,你可以简单地在HTML中使用缓存视图(cache-view)。不需要在控制器上使用它。 如果你想刷新页面,请使用<ion-view title="Dashboard" cache-view="false">。 但是,如果你想缓存你的页面,请使用<ion-view title="Dashboard" cache-view="true">或者简单地使用<ion-view title="Dashboard">


如果有人对我的答案给出-1的评分,请解释原因。我已经完成了这个任务,但是结果是错误的。 - Anuj
我下投票的原因是因为我在答案中写了我正在使用cache-view=true,但它并没有起作用 :) - Devid Farinelli
请为此创建一个 Plunker。缓存视图对我有效。 - Anuj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接