如何使用角度缓存来存储页面刷新?

时间:2015-05-18 16:19:19

标签: angularjs caching angular-cache

我试图使用angular-cache v4.2: angular-cache 我无法在页面刷新之间存储它。

我试图创建一个codepen,但由于我无法在那里注入模块,所以没有达到目标。 codepen

angular.module('myApp', ['angular-cache'])
  .config(function (CacheFactoryProvider) {
    angular.extend(CacheFactoryProvider.defaults, { maxAge: 15 * 60 * 1000 });
  })

但是,即使我创建了缓存,它也会在页面刷新时丢失缓存 - 我尝试了三种不同的存储类型,并且无法使用chrome版本39。< / p>

1 个答案:

答案 0 :(得分:0)

在Shehryar的评论的帮助下回答。参见:

codepen

 // To add to local storage
  localStorageService.set('localStorageKey','Now this!');
  // Read that value back
  $scope.value = localStorageService.get('localStorageKey');

使用角度本地存储模块,此示例将在页面刷新后存储缓存创建。也可以添加

localStorageService.clearAll();

然后刷新页面以删除初始值。