当我们想到template
在Angular2或Angular1.X 中使用时,我们知道下面是基本的写作方式之一:
template: './template-ninja.html'
使用Angular1.X,我们可以预先缓存所有模板,$templateCache.put()
如下所示:
var myApp = angular.module('Ninja', []);
myApp.run(function($templateCache) {
$templateCache.put('templateNinja.html', 'This is the content of the template-ninja');
});
Run Code Online (Sandbox Code Playgroud)
这将减少http请求的数量.我想知道如何使用Angular2实现相同的功能.有人可以帮忙吗?谢谢.
我还不知道有哪个库或工具可以缓存 Angular 2 的模板,但到目前为止,我很高兴只使用内联模板而不是外部文件。使用 es6 反引号字符作为模板,它允许您在 JavaScript 中编写多行 HTML 并将所有内容保存在一个文件中。
https://github.com/angular-in-action/chapter2/blob/master/client/components/dashboard.ts#L12
归档时间: |
|
查看次数: |
5343 次 |
最近记录: |