Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove helper HTML comments in Angular JS?

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"?

like image 659
user3089094 Avatar asked Dec 11 '13 00:12

user3089094


People also ask

Does angular remove HTML comments?

Unfortunately for my case, Angular removes all comments from the template during processing. Hence this first attempt resulted in an empty component. The setTimeout call is used in order for HTML rendering to complete before createComment is called.

How to remove HTML element in Angular?

Here the task is to remove a particular element from the DOM with the help of AngularJS. Approach: Here first we select the element that we want to remove. Then we use remove() method to remove that particular element.

How do I comment out HTML in AngularJS?

You can use HTML comment syntax instead <! -- --> . The HTML commented out this way still is added to the DOM but only as comment. Basically, because the template section is parsed as HTML not Javascript, I should be using HTML syntax for the comments, right?

How to remove HTML tags from string in AngularJS?

Whenever you require to strip HTML tags usign Angular Filter, then this post can help you. If you are working on php then it is very easily use predefine function But in AngularJS you need to make your own filter for remove html tag from string.


2 Answers

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

like image 66
Jeff Hubbard Avatar answered Sep 27 '22 23:09

Jeff Hubbard


You are able to remove the contents of these angular comments, as well as some of the classes angular attaches to elements (e.g ng-scope) by adding this config to your angular module:

myApp.config(['$compileProvider', function ($compileProvider)
{
    $compileProvider.debugInfoEnabled(false);
}]);

According to the angular.js docs, it is actually good to do this in production and should result in a performance boost.

like image 41
Eric Avatar answered Sep 27 '22 21:09

Eric