【发布时间】:2018-03-07 15:43:21
【问题描述】:
所以我在 Angular 存储库中发现了this 问题,他们要求相同,即 Angular 2 中 templateCache 的替代方案,但他们关闭它说您可以使用 CachedResourceLoader。
所以我的问题是如何使用这个 CachedResourceLoader 来替换 templateCache,我一直在 google 上搜索这个但找不到任何相关内容所以也许我没有指向正确的方向或者我错过了什么。
这个问题的答案可能是其他 2 个类似问题的有效答案。
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'
});
【问题讨论】:
-
这个问题没有具体说明你打算如何使用它。
-
我希望 Angular 2 具有与 Angular 1 提供的 templateCache 相同的功能。即第一次使用模板时,它会加载到模板缓存中以便快速检索。您可以将模板直接加载到脚本标签中的缓存中,或者直接使用 $templateCache 服务。
标签: javascript angularjs angular-templatecache