Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there a way to prevent Angular from creating "helper" HTML comments? For example,

<div ng-include="myTemplate"></div>

Will transform into something like

<!-- ngInclude: 'hurr-durr.html' -->
<div ng-include="myTemplate"></div>

How do I stop this? I've looked into the Angular source, and I've seen these "helpers" are generated by an unconditional document.createComment inside almost every directive, so I guess there's no way to stop them all at once by using a config setting on a provider or something. But maybe there is some custom Angular build without "helpers"? I suppose I could write some Yeoman/Grunt task to remove/comment the .createComment-s from Angular's source whenever I scaffold a new project. Or maybe you guys know of a fiddle that already does that? And also, this raises my last question: Are those comments somehow crucial to the Angular's normal functioning? And if I remove them, will it cause some kind of instability in my app? Should a just rewrite the CSS and "deal with it"?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The comments are crucial to how Angular handles certain elements. Removing them is not currently an option. What issues are you having with it?

share|improve this answer
    
Well my team stopped using HTML comments(replacing them with PHP comments) a while ago, since some browsers might match them for :first-child, :last-child, :nth-child and so on. Especially IE. –  user3089094 Dec 11 '13 at 0:49
    
I am interested, how does Angular depend on the comments? Do you have an example? –  Flek Dec 11 '13 at 0:51
    
@Flek Well, I know that you can have comment directives, i.e. <!-- Directive: myDirective --> instead of <div my-directive></div>, but I wasn't sure about the comments generated from actual attribute directives. –  user3089094 Dec 11 '13 at 0:53
    
The comments generated are used to find things like ng-if replacement nodes, ng-repeat elements, and so forth. Without them, how would ng-if know where to re-insert itself when the condition is true (coming back from being false)? –  Jeff Hubbard Dec 11 '13 at 0:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.