我试图在ng-repeat
中包含一个HTML代码片段,但是我无法使这些包含工作。看来的ng-include
目前的语法比它以前不同:我看到使用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
中读到这可能会导致问题,所以我用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
)。
是的,这一点我有一天。有点相关的答案http://stackoverflow.com/questions/13811948/different-ng-includes-on-the-same-page-how-to-send-different-variables-to-each/13812605#13812605 – jaime
原因这就是ng标签中的任何字符串实际上都被评估为一个角度表达式。 ''告诉它它是一个字符串表达式。 – Gepsens
@Gepsens:一旦你知道,它就有道理。如果文档提到它很明显,那将会很好。 – jacob