【发布时间】:2012-12-06 06:41:50
【问题描述】:
我试图在 ng-repeat 中包含一个 HTML sn-p,但我无法让包含工作。 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>
我的 sn-p 不是很多代码,但它有很多事情要做;我在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 html angularjs syntax include