【问题标题】:Ionic Caching not working离子缓存不起作用
【发布时间】:2016-07-26 17:52:24
【问题描述】:

我正在使用 Ionic 开发应用程序,但缓存未按预期工作。 每次我从root.home.notifs 切换到root.home.chats 时,chats 视图都会刷新(其控制器会重新初始化)。

我有 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>

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

.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')。更改此项会更改正确缓存的视图

关于如何解决这个问题的任何提示?

【问题讨论】:

    标签: caching ionic-framework


    【解决方案1】:

    尝试使用它来缓存前向视图$ionicConfigProvider.views.forwardCache(true);

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

      • 完成了,但我还是有同样的问题
      • 我认为 chache-view="true" 的问题使用这个:cache-view="false"
      • cache-view="true" 用于告诉 ionic 缓存视图,这就是我想要实现的。无论如何,尝试了cache-view="false",但它不起作用
      • 对不起,我的错,我的意思是你的拼写错误 chache-view="true",正确的是正确的
      【解决方案3】:

      您可以在 HTML 中使用缓存视图。无需在控制器上使用它。 如果您想刷新页面,请使用 &lt;ion-view title="Dashboard" cache-view="false"&gt; 。 但是如果你想缓存你的页面然后把&lt;ion-view title="Dashboard" cache-view="true"&gt;或者只是&lt;ion-view title="Dashboard"&gt;

      【讨论】:

      • 如果有人在我的答案上加上-1,请解释原因。我已经这样做了,这是错误的。
      • 我投反对票的原因是因为我在答案中写了我正在使用 cache-view=true 并且它不起作用:)
      • 请为此创建 plunker。缓存视图对我有用
      猜你喜欢
      • 2012-07-07
      • 2019-03-25
      • 2015-06-01
      • 2017-04-29
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多