我在本地开发单页应用程序.
我似乎无法使用Angularjs中的简单自定义指令将HTML文件作为模板加载.如果我尝试使用该template:属性的原始html ,它工作得很好但我有超过400行代码我需要在这个模板中使用,并且一旦我尝试使用templateUrl:任何负载.我尝试了30种可能的路径,包括将HTML文件复制到许多不同的位置,例如C:/my-customer.html,这是我的项目结构:
App--
|
css
|
img
|
js--
|
main.js
|
foundation.js
|
my-customer.html
|
templates--
|
my-customer.html
|
bcf.html
|
fluidType.html
|
start.html
|
my-customer.html
Run Code Online (Sandbox Code Playgroud)
保持简单我使用角文档中的示例这里是我的指令代码(在我的控制器的main.js内):
app.directive('myCustomer', function() {
return {
templateUrl: 'my-customer.html'
};
});
Run Code Online (Sandbox Code Playgroud)
再次,我尝试过路径,如:../my-customer.html ../templates/my-customer.html等等,但没有任何工作templateUrl:,我在Windows上没有本地Web服务器运行,如果这有帮助.
这是一些控制台错误,但作为一个新手不确定他们的意思,我有一种感觉,我需要运行一个Web服务器并解析通过http.
XMLHttpRequest cannot load file:///C:/Users/Dylan/Google%20Drive/PA/Dev/Grossing%20App/templates/my-customer.html. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.
angular.js:11594 Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load …Run Code Online (Sandbox Code Playgroud)