0

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

我试图创建一个codepen,但由于无法在其中注入模块而没有走得太远。密码笔

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

但是,即使我让它创建缓存,刷新页面时它也会丢失缓存 - 我尝试了三种不同的存储类型,但无法在 chrome 版本 39 上运行。

4

1 回答 1

0

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

密码笔

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

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

localStorageService.clearAll();

然后刷新页面,去掉初始值。

于 2015-05-19T09:02:07.743 回答