我用指令模板编写了单个文件。该文件使用 ng-include 指令附加到文档中。有时浏览器会在指令模板绑定(bind)之前加载模板,但并非总是如此。
https://plnkr.co/edit/SNhVU6BoM0nbOelJpepE?p=preview
在 ng-include
指令将 html 内容应用到文档之后以及绑定(bind)指令模板之后,是否有一些解决方案可以等待?也许我应该使用不同的解决方案将这些模板加载到 html 文档中。
最佳答案
Angular 有 2 种内置可能性:
- Yout 模板应位于直接包含在“index.html”中的文件中。 (同步模板)
<script src="templates.js"></script> in which: app.run(function($templateCache) { $templateCache.put('templateId', '<div></div>') })
- 每个模板应位于单独的文件
template1.html
、templat2.html
... (异步模板)
附注在开发过程中,模板始终位于单独的 html 文件中,对于生产使用,模板使用构建工具收集到 js 文件中。
关于javascript - Angular 模板指令绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42066686/