[英]ng-include in angular 1.2 not working?
I can't make the ng-include directive work. 我无法使ng-include指令工作。 I've watched and tried several solutions from stackoverflow but none of them seems to be working.
我已经从stackoverflow中观察并尝试了几种解决方案,但它们似乎都没有工作。 Am I missing something ?
我错过了什么吗? Angular works everywhere in the document, except for this.
Angular在文档中的任何地方都可以使用,除此之外。 The div is not emebeded in anything.
div不会被任何东西所束缚。
I am using the foundation framework. 我正在使用基础框架。 Is it possible that it causes the problem ?
是否有可能导致问题?
Here is the code in my index.html: 这是我的index.html中的代码:
<div ng-include="'partials/menu.html'"></div>
I checked and rechecked, I DO have a "partials" folder containing a "menu.html" file... 我检查并重新检查,我有一个包含“menu.html”文件的“partials”文件夹...
I have also tried: 我也尝试过:
<div ng-include src="'partials/menu.html'"></div>
and 和
<div ng-include="'/partials/menu.html'"></div>
Thanks in advance for any help you could give me ! 在此先感谢你能给我的任何帮助!
You have the correct code here: 你在这里有正确的代码:
<div ng-include=" 'partials/menu.html' "></div>
so it's most likely a path issue. 所以它很可能是路径问题。 If your partials folder is not inside the same folder as the html file you're calling the partial into, you might need something like
'../partials/menu.html'
. 如果你的partials文件夹不在html文件所在的文件夹中,那么你可能需要像
'../partials/menu.html'
这样'../partials/menu.html'
东西。 You might try creating a simple 'hello world' like partials/test.html with no angular functionality and use that to find the correct path and get your ng-include working. 您可以尝试创建一个简单的“hello world”,例如partials / test.html,没有角度功能,并使用它来查找正确的路径并让你的ng-include工作。
Thanks for your answer. 感谢您的回答。 I actually figured out what the problem was.
我实际上弄明白了问题是什么。 It seems you cannot do http requests in chrome on a local file.
看来你不能在本地文件的chrome中做http请求。 The console showed an error about that.
控制台显示错误。 I tried opening the file in firefox and it worked.
我尝试在firefox中打开文件,但它确实有效。 I assume this error will not occure once the file is uploaded on a server.
我假设一旦文件上传到服务器上就不会出现此错误。
The issue is the use of single and double quotation, you only need one of them, like this: 问题是使用单引号和双引号,你只需要其中一个,如下所示:
<div ng-include="partials/menu.html"></div>
This works as well 这也有效
<div ng-include='partials/menu.html'></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.