【问题标题】:Angular js simple ng-include not workingAngular js简单的ng-include不起作用
【发布时间】:2014-11-30 09:13:09
【问题描述】:

我是 Angular js 的新手。我正在尝试在我的页面中包含简单的 html 文件。

这是我的代码:

<!DOCTYPE html>
<html ng-app="">
<head>
</head>

<body ng-controller="userController">

<div class="container">
  <div ng-include src="'about.html'"></div>
</div>

<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>

</body>
</html>

about.html

<table class="table table-striped">
  <thead><tr>
    <th>Edit</th>
    <th>First Name</th>
    <th>Last Name</th>
  </tr></thead>
  <tbody><tr>
    <td>
      Edit
    </td>
    <td>ss</td>
    <td>dd</td>
  </tr></tbody>
</table> 

但它不包括“about.html”页面。

这段代码有什么问题?(抱歉英语不好)

提前致谢。

【问题讨论】:

  • 你能解决这个问题吗?我有同样的问题。如果您解决了这个问题,请发布解决方案。下面的答案对我不起作用。

标签: javascript angularjs angularjs-ng-include


【解决方案1】:

试试

<div ng-include="'about.html'"></div>

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

【讨论】:

  • 我尝试了与您的答案相同的示例,但我仍然无法包含新的 HTML 文件。我得到了Page not found error
  • 我刚刚复制了上面的示例并将 index.html 和 about.html 文件放在同一个文件夹中,并从正文中删除了 ng-controller,因为我没有带有控制器的 js 文件它对我来说效果很好。
  • 谢谢。你能看看我发的这个question吗。
【解决方案2】:

包含的文件 url 应该相对于包含页面的客户端 url。您可能正在使用某种抽象 URL 格式的 Web 框架。

您应该将包含的文件与其他静态文件放在一起。

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多