【问题标题】:template not loading using ng-include模板未使用 ng-include 加载
【发布时间】:2017-12-05 01:24:26
【问题描述】:

我了解了 ng-include 并将其用于模板,但我无法包含该页面。

index.html和menu.html在同一目录下,menu.html要加载到index.html中

<ng-include src="'menu.html'"></ng-include>

我已在 index.html 中包含应用程序的名称。 我想在页眉和页脚之间包含 menu.html。所以我删除了 menu.html 中的所有内容,除了我想要包含的容器 div。链接和引用也已在 index.html 中正确设置

我真的被困在这里了。请帮帮我!谢谢。

编辑: 这是我的项目结构 -

Project-
       app-
           fonts-...
           images-...
           scripts-
                   app.js
                   controllers.js
                   services.js
           styles-...
           index.html
           menu.html
       ...

编辑-2

我刚刚发现当我更改浏览器时,即从 chrome 到 firefox,它加载成功!现在为什么会发生这种情况?

【问题讨论】:

  • 你可以试试ng-include as &lt;div ng-include=" 'menu.html' "&gt;&lt;/div&gt;
  • @Maher 试过了。还是一样。
  • 好的,现在让我们看看您的应用程序结构,您能否通过将其添加到问题中来改进您的问题?
  • 另一种方法,从应用的根目录设置 url,例如ng-include=" '/Application/vendor/menu.html' "
  • 请问您是否检查了您的控制台,是否有任何消息或错误?

标签: angularjs angularjs-ng-include angularjs-templates


【解决方案1】:

你在使用网络服务器吗?

来自https://docs.angularjs.org/api/ng/directive/ngInclude

另外,浏览器的同源策略和跨域 资源共享 (CORS) 政策可能会进一步限制 模板已成功加载。例如,ngInclude 不适用于 所有浏览器上的跨域请求以及某些浏览器上的 file:// 访问 浏览器。

【讨论】:

  • 是的,这就是问题所在。因为更换浏览器后,它运行良好。我是这个领域的新手,所以你能用更简单的方式解释发生了什么吗?为什么 chrome 不起作用,而 firefox 起作用。还有什么我应该牢记在心,因为这样的东西很难找到!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
  • 2013-12-03
  • 1970-01-01
  • 2016-12-24
  • 1970-01-01
  • 2015-05-27
相关资源
最近更新 更多