【问题标题】:ng-include is not working even with single quotesng-include 即使使用单引号也不起作用
【发布时间】:2016-02-14 05:10:24
【问题描述】:

我正在关注本教程:http://campus.codeschool.com/courses/shaping-up-with-angular-js/level/4/section/1/video/1

我唯一不同的是在我的文件结构中添加了一个文件夹。 即使我将其删除并将“product-title.html”与我的 index.html 一起放在根目录中,它也不起作用。

<h3 ng-include="'includes/product-title.html'"></h3>

这看起来很简单,我做错了什么吗?

product-title.html中的代码是:

{{product.name | uppercase}}
<em class="pull-right">{{product.price | currency}}</em>

我正在使用以下依赖项:

"dependencies": {
    "angular": "^1.4.7",
    "bootstrap": "^3.3.5"
  }

【问题讨论】:

  • 你必须放完整路径而不是相对路径
  • 我也试过了。不走运.. ng-include="'/includes/product-title.html'"
  • 你能显示你的目录结构吗?
  • 也是错误productController not found吗?
  • 添加了结构。我遇到的错误是:XMLHttpRequest 无法加载 file:///C:/includes/product-title.html。跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。

标签: javascript angularjs include frontend


【解决方案1】:

根据你提到的错误

XMLHttpRequest 无法加载 file:///C:/includes/product-title.html。 跨域请求仅支持协议方案:http、 数据、chrome、chrome-extension、https、chrome-extension-resource。

不能点击html文件直接运行,必须在Apache等本地服务器上运行

【讨论】:

  • 是的,一旦我看到那个错误,我就知道它是什么。现在问起来有点傻。我使用了 IIS 并让它工作。谢谢!
【解决方案2】:

如果您使用的是 Mac,您可以这样做:

  1. 打开终端并转到您的 Angular 项目文件夹
  2. 输入php -S localhost:3000(或其他端口,随便)
  3. 在浏览器上,访问此地址并...完成!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-27
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多