我想预加载模块所需的所有AngularJS模板。当模板已经组合成一个文件时,我找不到任何方法来做到这一点。
例如,我有一个名为"templates.html"的html文件,其结构如下:<script type='text/ng-template' id='directive1.html'>
<p>Directive One</p>
</script>
<script type='text/ng-template' id='directive2.html'>
<p>Directive Two</p>
</script>
我的指令将它们的templateUrls适当地设置为directive1.html
和directive2.html
。
我想做的是让模块在启动时加载templates.html
文件并缓存所有模板。
我已经找到了这样的例子,但只有当指令模板在单独的文件中,而不是当它们已经组合在一起时。
理想情况下会有一个$templateCache.load("/templates.html")
方法,但我还没有发现这样的事情。
你可能想使用这个伟大的grunt任务:grunt-angular-templates。
我正在使用它。
它将完成缓存您指定的所有模板的整个任务。
因此,directive1.html
和directive2.html
将被缓存