我知道如何从缓存中删除所有模板
$templateCache.removeAll();
但我只想从缓存中删除特定模板。
该模板不是从 $routeProvider
加载的,而是通过使用
templateUrl: 'template/page/file.html'
我的应用结构是这样的
-web
- js
- controllers
- appController.js
- templates
- page
- file.html
我在 appController.js 中做了 $templateCache.remove('/templates/page/file.html');
最佳答案
$templateCache基于 $cacheFactory由于后者有一个 .remove(key),它也适用于您的 $templateCache。也许你拿错 key 了?
您可以尝试调用 .get(key)
来检查您是否拥有正确的 key (我怀疑您没有 - 这就是 .remove(key) 的原因
对你不起作用)。
也许您的模板文件的路径弄乱了 key ,相对路径可能不是实际 key ,而是完整路径或单独的文件名。
关于javascript - Angular : Remove a specific template from cache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41363836/