ng-include似乎什么都不做

时间:2013-04-16 02:21:30

标签: angularjs angularjs-directive

http://jsfiddle.net/fresheyeball/5z7bX/

<script type="text/ng-template" id="/newTrack.html">
  <h1>New Track </h1>
  <p>Hello there</p>
</script>
<div id="overlay" closemodal></div>
<div id="modal"><a id="closeModal" closemodal></a>
    <div id="modalContent" ng-include src="/newTrack.html"></div>
</div>

我希望得到以下结果:

<div id="overlay" closemodal></div>
<div id="modal"><a id="closeModal" closemodal></a>
    <div id="modalContent" ng-include src="/newTrack.html">
       <h1>New Track </h1>
       <p>Hello there</p>
    </div>
</div>

但似乎没有任何事情发生。实际上我正在尝试从自定义指令中渲染模板,在跟踪它一段时间后,看起来即使以最简单的形式我也无法使ng-include工作。我在这里缺少什么?

1 个答案:

答案 0 :(得分:5)

在小提琴选项下,添加<body ng-app>

  

src:如果源是字符串常量,请确保将其用引号括起来,例如src="'myPartialTemplate.html'"。 - ngInclude docs

所以ng-include src="'/newTrack.html'"

Fiddle