【发布时间】:2015-05-18 09:34:25
【问题描述】:
我试图在第一页查看时获取所有部分,以便在查看应用程序期间不会下载任何 html。
一种方法是在index.html 中使用模板。
<script type="text/ng-template" id="templateId.html">
<p>This is the content of the template</p>
</script>
- 这样你就有超过5个模板
index.html文件变成 难以管理并破坏了项目的模块结构。
另一种方法是在.js 文件中包含html,很可能在app.js 中
myApp.run(function($templateCache) {
$templateCache.put('templateId.html', 'This is the content of the template');
});
- 我认为
.js文件不适合存放 html 代码,同样的问题 就像在index.html中一样。
我想做的是在不同的文件中有模板,这样我就可以保持我的模块结构并将它们预加载到索引上。
这就是我现在所拥有的。
var cmsAppFirstRun = function ($templateCache, $templateRequest, $rootScope) {
$templateRequest('views/common/top-bar.html').then(function (response) {
$templateCache.put('top.bar', response);
$rootScope.templatesDone = true;
});
};
angular.module('cmsApp').run(cmsAppFirstRun);
还有html
<div ng-include="'top.bar'" ng-if="$root.templatesDone"></div>
有没有更性感、更棱角分明的方式来做到这一点?
【问题讨论】:
标签: angularjs angularjs-ng-include