使用 ng-include 包含 html 文件时出错

Error Occuring while including html file using ng-include

我在使用 ng-include.

包含 html 文件时遇到以下错误
XMLHttpRequest cannot load file:///home/algo/Dnyaneshwar/Angular/TestProject/views/header1.html. 
Cross origin requests are only supported for protocol schemes: 
http, data, chrome, chrome-extension, https, chrome-extension-resource.

问题原因
发生此错误是因为您只是试图直接从浏览器打开 html 文档。由于您使用的是 file:// 或 C:/,这就是错误提示它们不是 http:// 或 https:// 的原因。
不要尝试 运行 它直接通过文件夹。

如何修复
您需要通过网络服务器访问您的代码并在本地主机上访问它。如果您安装了 eclipse 或 apache,请使用它来访问您的文件。一些 IDE 像 intellij,eclipse 已经内置了网络服务器。

如果您设置了节点,那么只需 运行 npm install http-server -g,您就可以在终端中使用它,例如 http-server C:\path\to\app

另请参阅