I'm having trouble figuring out what's in my template cache. When I google, all I find is this: https://docs.angularjs.org/api/ng/service/$templateCache I'm looking for documentation on all the methods available for that but can't find it. But really all I want to know is how to list all the keys in the templateCache. How is that done?
I think you can use $provide.decorator
to wrap the put
method and keep a list of the keys in the cache as they are added. You can then use the same idea to also add a new method to the cache factory that returns said list.
You can see an example implementation here, should be quite easy to adapt it to your needs: https://github.com/angular/angular.js/pull/3760#issuecomment-130343142 (pasted here for reference).
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;
}
]);
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With