angularjs – 如何列出模板缓存中的所有内容?
发布时间:2020-12-17 07:12:40 所属栏目:安全 来源:网络整理
导读:我无法弄清楚模板缓存中的内容.当我谷歌时,我发现的是: https://docs.angularjs.org/api/ng/service/ $templateCache我正在寻找有关所有可用方法的文档,但找不到它.但我真的想知道的是如何列出templateCache中的所有键.怎么做的? 解决方法 我认为您可以使
我无法弄清楚模板缓存中的内容.当我谷歌时,我发现的是:
https://docs.angularjs.org/api/ng/service/ $templateCache我正在寻找有关所有可用方法的文档,但找不到它.但我真的想知道的是如何列出templateCache中的所有键.怎么做的?
解决方法
我认为您可以使用$provide.decorator来包装put方法,并在添加时保留缓存中的键列表.然后,您可以使用相同的想法将新方法添加到返回所述列表的缓存工厂.
您可以在这里看到一个示例实现,应该很容易适应您的需求: 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; } ]); }]); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |