内嵌`NG-template`不是'NG-include`发现 [英] Inline `ng-template` not found by `ng-include`
问题描述
我有一个观点被加载了嵌入式这是不被用
后的文件中。该脚本块坐镇视图文件的顶部:找到的文本/ NG-模板
NG-包括
<脚本类型=文/ NG-模板ID =stringCondition>
<! - 模板胆量 - >
< / SCRIPT>
对此我后来装在文件中:
< NG-包括SRC ='stringCondition'>< / NG-包括>
不过是生产在控制台404错误:
GET HTTP://本地主机/〜我/ stringCondition 404(未找到)
我试过的命名(就像上的.html结束),使用几个变种 NG-包括
作为一个属性,而不是高水平的元素。所有没有运气。
这可能是导致嵌入 NG-模板
不具有 NG-包括
在同一个被注册视图文件?
更新:
由于意见和回答指出,我的code的基本设计是正确的。但有些事情是造成 NG-模板
来(显然)不使模板系统可用。
我更新了我的code从一个HTML文件(而不是一个嵌入模板)拉并能正常工作。
有没有我可以运行到该休息 NG-模板的常见情况
?
< DIV NG-应用>\r
<脚本类型=文/ NG-模板ID =stringCondition>\r
是的,是的,它做到了。\r
< / SCRIPT>\r
有效吗? < NG-包括SRC ='stringCondition'>< / NG-包括>\r
< / DIV>\r
\r
&LT;脚本src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js\"></script>$c$c>$p$p>\r
我有同样的问题,在这篇文章就来了。我现在可以看到是什么原因造成这个问题,所以希望这是帮助别人这个问题。
原因rgthree的code工作原理是,文本/ NG-模板脚本标签有NG-应用的范围内生活。因此,它是罚款,有模板,在一个单独的.js文件,但只是确保当HTML页面是NG-应用程序内上呈现,否则角不会意识到这一点,并会尝试从加载它服务器。
I have a view being loaded with an embedded text/ng-template
which is not being found by a ng-include
later in the file. The script block sits at the very top of the view file:
<script type="text/ng-template" id="stringCondition">
<!-- template guts -->
</script>
Which I am loading later in the file with:
<ng-include src="'stringCondition'"></ng-include>
But is producing a 404 error in the console:
GET http://localhost/~me/stringCondition 404 (Not Found)
I've tried several variants on naming (like having .html on the end) and using ng-include
as an attribute instead of the high level element. All with no luck.
What could be causing an embedded ng-template
to not be registering with an ng-include
in the same view file?
UPDATE:
As comments and answers have pointed out, the basic design of my code is correct. But something is causing ng-template
to (apparently) fail to make the template available to the system.
I updated my code to pull from a HTML file (instead of an imbedded template) and it works fine.
Is there a common situation that I could be running into that breaks ng-template
?
<div ng-app>
<script type="text/ng-template" id="stringCondition">
Yes, yes it did.
</script>
Did it work? <ng-include src="'stringCondition'"></ng-include>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
I had the same problem and came upon this post. I can now see what is causing this issue so hopefully this is helps anyone else with this issue.
The reason rgthree's code works is that the script tag for text/ng-template has to live within the scope of ng-app. So it is fine to have the template in a seperate .js file but just make sure when it is rendered on the HTML page it is within ng-app, otherwise angular won't be aware of it and will attempt to load it from the server.
这篇关于内嵌`NG-template`不是'NG-include`发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!