AngularJS 在 HTML 中留下注释:是否可以删除它们? [英] AngularJS leaves comments in HTML: is it possible to remove them?

查看:17
本文介绍了AngularJS 在 HTML 中留下注释:是否可以删除它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以删除html代码中留下的角度注释?

Does anyone knows if you can remove the angular comments that are left in html code?

例如:如果我使用 ngRepeat 并且没有要重复的项目,AngularJS 会留下这个:

For example: If I use ngRepeat and there are no items to repeat over, AngularJS leaves this :

<!-- ngRepeat: post in posts -->

推荐答案

此注释是 ngRepeat 执行的 element 嵌入的结果.看起来它几乎从一开始就发生了(以角度而言)并且每当指令要求元素嵌入时都会创建.

This comment is a result of the element transclusion performed by ngRepeat. Looks like it's been happening nearly since the dawn of time (in angular terms) and will be created whenever a directive asks for element transclusion.

虽然您当然可以通过直接的 HTML 操作来消除它,但这样做并不安全.通读源代码后,它表明一旦原始 ngRepeat 元素被删除,就需要此注释来继续编译您的 HTML.此外,在 v1.2.0 中,ngRepeat 添加更多评论 用于确定放置重复元素的位置.

While you certainly could wipe it out with direct HTML manipulation, it's not a safe thing to do. Having read through the source, it suggests this comment is needed to continue compiling your HTML once the original ngRepeat element is removed. Additionally, in v1.2.0, ngRepeat adds more comments that are used to determine where repeated elements are placed.

总结:

  • Angular 不允许你删除它
  • 您可以手动完成,但很可能会破坏角度
  • 重申这些评论,首先删除此评论似乎是一个奇怪的请求 - 根据您这样做的原因,可能有更好的选择来实现您想要实现的目标.立>
  • Angular doesn't let you remove this
  • You could do it manually but you would most likely break angular
  • To reiterate the comments, it seems a strange request to remove this comment in the first place - depending on your reasoning for doing this there may be better options for what you want to achieve.

这篇关于AngularJS 在 HTML 中留下注释:是否可以删除它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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