【发布时间】:2017-10-27 12:59:46
【问题描述】:
我尝试了一段时间,但没有运气。
我正在使用 angularjs。我正在使用@templateCache。 https://docs.angularjs.org/api/ng/service/$templateCache
假设我有一个命名为 'foo' 的 angularjs 指令,该指令的模板是 'foo.html'。在这个'foo.html'中,我有以下代码:
<h1>Below script is for template cache purpose</h1>
<script type="text/ng-template" id="templateId.html">
<p>This is the content of the template</p>
</script>
在我的另一个 HTML 中,假设为“bar.html”。在这个html中,我有<foo></foo>,它只加载<h1>Below script is for template cache purpose</h1>,但是当我检查$templateCache.get('foo.html')时,它没有这个'foo.html'。
尝试了很多方法后,我不知道如何解决我的问题。
附:如果我
<script type="text/ng-template" id="templateId.html">
<p>This is the content of the template</p>
</script>
直接在“bar.html”中。 $templateCache.get('foo.html') 可以获取 'foo.html'。但我不想直接放入'bar.html',因为我有很多,我想在单独的文件中保持干净,也不要破坏当前代码。
补充问题:如果<foo></foo> 在我的'bar.html' 中有效,我不想让'foo.html' 的<h1></h1> 出现在'bar.html' 中。我让<foo ng-if = "false"></foo> 在'bar.html' 中吗?还是有其他方法可以做到这一点?将所有 <script></script> 添加到一个新的 'script.js' 文件中,并让 <script src="script.js"></script> 在 'foo.html' 和 'bar.html' 中?
【问题讨论】:
-
所以,问题是为什么它包含
<script>或不包含<script>- 你的标题暗示它did,你的问题暗示它didn 't -
抱歉,我的标题有错字。它没。我修正了标题。
标签: javascript html angularjs angular-templatecache