ng-include编译为注释 [英] ng-include compiles to a comment

查看:66
本文介绍了ng-include编译为注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角度应用程序,想要在模板中添加其他作为div. ng-include似乎是一个完美的选择.

I have an angular app, and want to in a template, add other as divs. ng-include seemed like a perfect choice.

在main.html

In main.html

<div id="page-wrapper">
<div ng-include src="'/partials/module.html'"></div>
</div>

在module.html

In module.html

<div class="module">
<h1>Module</h1>
</div>

所有文件都位于应用程序的局部文件夹中.

All files live in the partials-folder in the app.

运行此代码时,在html代码中的位置,我得到<!-- ngInclude: -->,然后用也受支持的ng-include标记替换main.html中的div,它将编译为<!-- ngInclude: undefined -->.

When running this, at the place in the html code, I get <!-- ngInclude: -->, and substituting the divs in main.html with the also supported ng-include tag, it compiles to <!-- ngInclude: undefined -->.

有人知道这可能是什么问题吗?

Does anyone know what might be the problem?

推荐答案

在将ng-include用作元素时,只能使用src =":

You only use src="" when using ng-include as an element:

<ng-include src="'/partial.html'"></ng-include>

将ng-include用作属性时,请将部分URL放在属性本身中:

When using ng-include as an attribute, you put the partial URL right in the attribute itself:

<div ng-include="'/partial.html'"></div>

请参见 https://docs.angularjs.org/api/ng/directive/ngInclude 用于两个用例.

这篇关于ng-include编译为注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆