【问题标题】:ng-include not loading partial viewng-include 不加载部分视图
【发布时间】:2017-06-30 02:36:41
【问题描述】:

我目前正在做一个项目,但我遇到了一些问题。无论我尝试做什么,ng-include 都无法加载我在另一个文件夹中的部分视图。

我想在分页文件夹中加载view.html 文件。我的文件位于与分页文件夹处于同一级别的文件夹中。

这是我的站点视图片段

<div class="container">
  <div class="col-sm-6" id="NEWS">
    <div class="well" ng-repeat="info in news">
      <p>
        {{info.description}}
      </p>
    </div>
    <ng-include src="'/pagination/view.html'"></ng-include>
  </div>
</div>

我的view.html 有一个caption test 用于测试目的。

我也尝试使用此代码:

<div ng-include src=....
<div ng-include="....
<ng-include src="'../pagination/view.html".

似乎没有任何效果。有人知道是什么问题吗?

【问题讨论】:

  • 为什么不使用 templateUrl 创建一个目录并包含该目录?

标签: angularjs angularjs-ng-include


【解决方案1】:

我的文件位于与分页文件夹处于同一级别的文件夹中。

您可能为 html 模板传递了错误的路径。

您必须像在index.html 文件中一样引用您的模板目录。所以无论ng-include指令存在哪个html模板,你都必须给它路径,就好像你的根是index.html存在的地方一样。

同时尽量避免在路径前使用“/”。

例如

假设您有以下文件夹树:

---index.html

---/templates/app.html

---/tempates/pagination/view.html

如果您尝试在您的app.html 中包含view.html,那么您可以这样做:

<ng-include src="'templates/pagination/view.html'"></ng-include>

希望对你有帮助。

【讨论】:

    【解决方案2】:

    造成这种类型错误的原因是

    1. 为 html 模板传递了错误的路径。
    2. 传递路径不是小写的。 在 angularJS 中,所有引用路径都必须是小写的,比如
    <div ng-include="'/content/patna/partials/skive/test-partial.html'"></div>
    
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 2014-06-30
      • 2015-05-31
      • 2016-01-07
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      相关资源
      最近更新 更多