我正在尝试在内添加HTML代码段ng-repeat,但无法使用包含功能。看来的当前语法与ng-include以前的语法不同:我看到许多示例使用
ng-repeat
ng-include
<div ng-include src="path/file.html"></div>
但是在官方文档中,它说使用
<div ng-include="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>
我的代码片段不是很多代码,但是有很多事情要做。这可能会引起问题,所以我sidepanel.html只用单词代替了内容foo,仍然一无所获。
sidepanel.html
foo
我还尝试过直接在页面中声明模板,如下所示:
<script type="text/ng-template" id="tmpl"> foo </script>
并遍历了ng-include引用脚本的所有变体id,仍然一无所获。
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)。
src="views/sidepanel.html"
您必须src在双引号内将字符串单引号引起来:
src
<div ng-include src="'views/sidepanel.html'"></div>