我试图在 ng-repeat
中包含一个 HTML 片段,但我无法让包含工作。似乎 ng-include
的当前语法与以前的不同:我看到很多示例使用
<div ng-include src="path/file.html"></div>
但在 official docs ,它说使用
<div ng-include="path/file.html"></div>
然后down the page它显示为
<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
这可能会导致问题,因此我将 sidepanel.html
的内容替换为仅单词 foo
,仍然没有。
我也试过像这样直接在页面中声明模板:
<script type="text/ng-template" id="tmpl">
foo
</script>
并通过引用脚本的 id
的所有变体 ng-include
,仍然没有。
我的页面包含更多内容,但现在我将其精简为以下内容:
<!-- 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
).
最佳答案
关于javascript - ng-include 的正确语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13943471/