I'm trying to get all my partials at first page view, so that during application viewing no html is downloaded.
One way is by having templates in index.html
.
<script type="text/ng-template" id="templateId.html">
<p>This is the content of the template</p>
</script>
- This way is you have more than 5 templates
index.html
file becomes unmanageable and breaks module structure of project.
Another way of doing this is to have html in .js
file, most likely in app.js
myApp.run(function($templateCache) {
$templateCache.put('templateId.html', 'This is the content of the template');
});
- I think
.js
file is no place for html code and again same problems as with having it inindex.html
.
What I would like to do, is have templates in different files, so I can keep my modules structure and preload them on index.
This is what I have now.
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);
And html
<div ng-include="'top.bar'" ng-if="$root.templatesDone"></div>