所以我在Angular repo中发现this问题,他们要求相同的,即Angular 2中templateCache的替代方法,但他们关闭它说你可以使用CachedResourceLoader。
所以我的问题是如何使用这个CachedResourceLoader更换templateCache,我一直在寻找关于这个谷歌,但找不到任何相关的内容,所以也许我没有指向正确的方向还是我错过了什么。
对于这个问题的答案可能是其他两个类似问题的有效答案。
代码示例将templateCache在AngularJS提供的功能:
添加:
var myApp = angular.module('myApp', []);
myApp.run(function($templateCache) {
$templateCache.put('templateId.html', 'This is the content of the template');
});
通过$ templateCache检索:
$templateCache.get('templateId.html')
或检索:
myApp.component('myComponent', {
templateUrl: 'templateId.html'
});
该问题未指定您打算如何使用它。 – estus
我想为angular 2提供与为angular 1提供的templateCache相同的功能。即,第一次使用模板时,它会加载到模板缓存中以便快速检索。您可以直接在模板标签中将模板加载到缓存中,也可以直接使用$ templateCache服务。 – Javiere