ng-include 即使使用单引号也不起作用

ng-include is not working even with single quotes

我正在学习本教程: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"
  }

根据您提到的错误

XMLHttpRequest cannot load file:///C:/includes/product-title.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

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

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

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