我无法弄清楚模板缓存中的内容.当我谷歌时,我发现的是:
https://docs.angularjs.org/api/ng/service/ $templateCache我正在寻找有关所有可用方法的文档,但找不到它.但我真的想知道的是如何列出templateCache中的所有键.怎么做的?
解决方法
我认为您可以使用$provide.decorator来包装put方法,并在添加时保留缓存中的键列表.然后,您可以使用相同的想法将新方法添加到返回所述列表的缓存工厂.
您可以在这里看到一个示例实现,应该很容易适应您的需求:
https://github.com/angular/angular.js/pull/3760#issuecomment-130343142(粘贴在这里供参考).
app.config(['$provide',function($provide) { // monkey-patches $templateCache to have a keys() method $provide.decorator('$templateCache',[ '$delegate',function($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; } ]); }]);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。