Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 从Angular cacheFactory获取密钥大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我列出$cacheFactory对象时,它有几个方法,但我没有看到实际的键/值缓存.

假设您正在查看$http缓存,$cacheFactory($http)如何获取当前缓存的密钥列表或理想情况下的密钥和值?

解决方法

使用$cacheFactory的装饰器添加getKeys方法

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<body ng-app="decorateExample">

  <script>
  function cacheProvider($providE) 
    {
    // monkey-patches $templateCache to have a keys() method
    $provide.decorator('$templateCache',['$delegate',cacheDelegator]);
    }
                                          
  function cacheDelegator($delegatE) 
    {
    var keys = [],origPut = $delegate.put;

    $delegate.put = function(key,value) 
      {
      origPut(key,value);
      keys.push(key);
      };

    // we would need cache.peek() to get all keys from $templateCache,but this features was never
    // integrated into Angular: https://github.com/angular/angular.js/pull/3760
    // please note: this is not feature complete,removing templates is NOT considered
    $delegate.getKeys = function() 
         {
         return keys;
         };

    return $delegate;
    }
  
angular.module('decorateExample',[]);
  
angular.module('decorateExample').config(['$provide',cacheProvider]);
</script>

</body>

> AngularJS Issue #3760: Update cacheFactory.js: Added peek() for returning all keys
> Decorate Core Directives in Angular

大佬总结

以上是大佬教程为你收集整理的angularjs – 从Angular cacheFactory获取密钥全部内容,希望文章能够帮你解决angularjs – 从Angular cacheFactory获取密钥所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。