gpt4 book ai didi

angularjs - 如何列出模板缓存中的所有内容?

转载 作者:行者123 更新时间:2023-12-02 22:30:31 24 4
gpt4 key购买 nike

我无法确定模板缓存中的内容。当我谷歌时,我发现的是: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;
}
]);
}]);

关于angularjs - 如何列出模板缓存中的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com