一个简单的 ng-include
会导致页面在页面的一个区域中一遍又一遍地递归打印出整个站点,这会导致浏览器崩溃。如果我改变路径,同样的事情会发生,所以显然它甚至没有看路径。如果我在页面的任何地方使用 ng-include
,同样的奇怪行为也会发生。
模板 (list.html) 位于 angularjs 脚本所在的子文件夹中。
HTML
<div ng-if="comments_data">
<div ng-include="'templates/list.html'"></div>
</div>
模板
<li ng-repeat="comment in comments_data">
{{ print_some_stuff }}
</li>
最佳答案
你能试试吗:
<div ng-if="comments_data">
<div ng-include="'/templates/list.html'"></div>
</div>
路径开头的斜杠对我来说是个问题。检查您的路由器并查看模板的加载方式(应该与前导斜线相同)。
关于javascript - AngularJS 奇怪的行为,NG-INCLUDE 导致整个页面重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27001069/