Does anyone knows if you can remove the angular comments that are left in html code?
For example: If I use ngRepeat and there are no items to repeat over, AngularJS leaves this :
<!-- ngRepeat: post in posts -->
There's nothing too much to explain this feature. It does what the title says, removes every HTML comment. Everything written between the <! -- beginning and --> closing tag is considered a comment.
You can use HTML comment syntax instead <! -- --> . The HTML commented out this way still is added to the DOM but only as comment.
How to Write Inline Comments in HTML. You can also add comments in the middle of a sentence or line of code. Only the text inside the <! -- --> will be commented out, and the rest of the text inside the tag won't be affected.
To write HTML comments put <! --- and ---> at either end of the comment. HTML comments are notes to keep HTML code organized and are ignored by the browser.
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.
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.
To summarise:
Run this in your dev console to nuke the comments:
$("*").contents().filter(function(){ return this.nodeType == 8;}).remove();
Not a proper fix, but handy snippet while debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With