ng-include seems to do nothing

馋奶兔 提交于 2019-12-24 12:17:24

问题


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>

I would expect the following result:

<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>

But nothing seems to happen. Really I am trying to render the template from inside a custom directive, after tracking it down for a while, it appears I can't get ng-include to working even in its most simple form. What am I missing here?


回答1:


Under Fiddle Options, add <body ng-app>

src: If the source is a string constant, make sure you wrap it in quotes, e.g.,src="'myPartialTemplate.html'". -- ngInclude docs

So ng-include src="'/newTrack.html'"

Fiddle



来源:https://stackoverflow.com/questions/16027701/ng-include-seems-to-do-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!