我想在ng-repeat
中包含一个HTML片段,但是我无法使它正常工作。似乎当前的ng-include
语法与以前不同:我看到很多示例使用
<div ng-include src="path/file.html"></div>
但是在官方文档中,建议使用。
<div ng-include="path/file.html"></div>
然而,在页面下方它被展示为:
<div ng-include src="path/file.html"></div>
无论如何,我试过了。
<div ng-include="views/sidepanel.html"></div>
<div ng-include src="views/sidepanel.html"></div>
<ng-include src="views/sidepanel.html"></ng-include>
<ng-include="views/sidepanel.html"></ng-include>
<ng:include src="views/sidepanel.html"></ng:include>
我的代码片段并不是很多,但是它里面发生了很多事情;我在Dynamically load template inside ng-repeat
中看到可能会有问题,所以我用单词foo
替换了sidepanel.html
的内容,但仍然没有任何反应。
我还尝试在页面中直接声明模板,就像这样:
<script type="text/ng-template" id="tmpl">
foo
</script>
尝试使用所有 ng-include
引用脚本的 id
,但仍然没有效果。
我的页面有很多内容,但现在我已将其简化为以下内容:
<!-- index.html -->
<html>
<head>
<!-- angular includes -->
</head>
<body ng-view="views/main.html"> <!-- view is actually set in the router -->
<!-- views/main.html -->
<header>
<h2>Blah</h2>
</header>
<article id="sidepanel">
<section class="panel"> <!-- will have ng-repeat="panel in panels" -->
<div ng-include src="views/sidepanel.html"></div>
</section>
</article>
<!-- index.html -->
</body>
</html>
标题栏已经显示了,但是我的模板没有出现。我在控制台或 Node 中没有收到任何错误信息,并且如果我在开发工具中单击 src="views/sidepanel.html"
中的链接,它会带我到我的模板(并显示foo
)。