【问题标题】:including html template, ng-include doesn't work包括 html 模板,ng-include 不起作用
【发布时间】:2018-07-18 00:47:09
【问题描述】:

我正在使用 angularJS 进行个人项目。我在线下载了这个 html 模板,当我测试该模板时,它运行良好。问题是,当我尝试使用 ng-include 将模板中的页面包含到我的项目中时,没有任何反应,没有错误,但也没有显示任何内容,只是一个空白页面。 基本上我的项目结构如下:

  • src > app > template > index.html(这是模板主页的位置)。

  • src > app > components > home > home.component.html(我项目的主页)

基本上我想在 home.component.html 中包含 index.html,但是 ng-include 不起作用:/

这是我在 home.component.html 中的代码:

<div ng-app = "" ng-controller = "homeController">
  <div ng-include = "'/app/template/index.html'"> </div>
</div>

非常感谢:)

【问题讨论】:

  • 您是否在控制台工具的网络选项卡上收到错误消息?我希望它正在尝试找到您的文件,但没有在 ng-include 位置找到它。看起来您的包含在 app/trueshoes 中查找,但在您的问题中,您说 index.htmlapp/template 中。
  • 哦,对不起,我刚刚意识到,这只是一个错字,它是 /app/template/index.html,我在我的问题中更正了它
  • 我在控制台上没有任何错误
  • 您是否在 html 中包含角度源文件并且它们是否正确加载?您可以在控制器中执行console.log() 吗?

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


【解决方案1】:

你只需要放模板的方式,像这样:

<div ng-app = "" ng-controller = "homeController">
    <div ng-include = "'/template/index.html'"> </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-07
    • 2015-02-20
    • 1970-01-01
    • 2016-12-24
    • 2015-04-04
    • 2017-08-03
    • 2015-12-22
    相关资源
    最近更新 更多